P2PySonar2demo_project/pysonar_demo/models.pyView source
pysonar_demo/models.pyStatic analysis
Domain classes, constructors, and computed state.59 definitions69 references
   1 """Domain models used by the demo application."""
   2
   3
   4 class Market:
   5     def __init__(self, question: str, yes_price: float, volume: int):
   6         self.question = question
   7         self.yes_price = yes_price
   8         self.volume = volume
   9
  10     @property
  11     def display_name(self) -> str:
  12         return self.question + " · " + self.liquidity_label()
  13
  14     def liquidity_label(self) -> str:
  15         if self.volume >= 100000:
  16             return "deep"
  17         if self.volume >= 50000:
  18             return "active"
  19         return "emerging"
  20
  21
  22 class Prediction:
  23     def __init__(self, market: Market, score: float, confidence: str):
  24         self.market = market
  25         self.score = score
  26         self.confidence = confidence
  27
  28     def summary(self) -> str:
  29         direction = "YES" if self.score >= 0.5 else "NO"
  30         return direction + " · " + self.confidence + " · " + self.market.display_name
  31
  32
  33 class Report:
  34     def __init__(self, title: str, predictions: list[Prediction]):
  35         self.title = title
  36         self.predictions = predictions
  37
  38     def strongest(self) -> Prediction:
  39         best = self.predictions[0]
  40         for prediction in self.predictions[1:]:
  41             if prediction.score > best.score:
  42                 best = prediction
  43         return best