Selaa lähdekoodia

Adds NPC DROP if volume of shares increases

Foppe Hemminga 6 vuotta sitten
vanhempi
commit
9e954310a2
3 muutettua tiedostoa jossa 27 lisäystä ja 5 poistoa
  1. 6 2
      main.py
  2. 13 0
      model.py
  3. 8 3
      view.py

+ 6 - 2
main.py

@@ -28,8 +28,11 @@ def process_drop(this_stock):
     current_price = float(data_latest.current_price)
     quantity = data_latest.available_shares - data_previous.available_shares
     stock_name = this_stock[0]
+    npc_drop = False
+    if model.is_npc_drop(data_previous, data_latest):
+        npc_drop = True
     message = view.create_message(
-        stock_name, timestamp_latest, current_price, quantity)
+        stock_name, timestamp_latest, current_price, quantity, npc_drop=npc_drop)
     print(message)
     if is_drop:
         view.broadcast(message)
@@ -57,7 +60,8 @@ def process_forecast(this_stock):
     stock_name = this_stock[0]
     current_quantity = data_latest.available_shares
     message = view.create_message(
-        stock_name, timestamp_latest, current_price, quantity, current_quantity, forecast_previous, forecast_latest)
+        stock_name, timestamp_latest, current_price, quantity, current_quantity,
+        forecast_previous, forecast_latest, False)
     print(message)
     if is_forecast_changed:
         view.broadcast(message)

+ 13 - 0
model.py

@@ -88,6 +88,19 @@ def process_data(data_previous, data_latest, price, threshold):
     return this_drop
 
 
+def is_npc_drop(data_previous, data_latest):
+    """
+    A NPC drop is characterized by a spike in available shares
+    :param data_previous:
+    :param data_latest:
+    :return:
+    """
+    npc_drop = False
+    if data_latest.available_shares - data_previous.available_shares > 0:
+        npc_drop = True
+    return npc_drop
+
+
 def process_forecast(data_previous, data_latest, max_price, available):
     forecast_changed = False
     if data_previous.forecast in ("Very poor", "Poor", "Average"):

+ 8 - 3
view.py

@@ -3,7 +3,8 @@ from datetime import datetime
 import requests
 
 
-def create_message(name, timestamp, price, quantity, current_quantity=0, forecast_previous="", forecast_latest=""):
+def create_message(name, timestamp, price, quantity, current_quantity=0, forecast_previous="",
+                   forecast_latest="", npc_drop=False):
     """
     Creates the string to be broadcast
     :param name:
@@ -13,12 +14,16 @@ def create_message(name, timestamp, price, quantity, current_quantity=0, forecas
     :param current_quantity:
     :param forecast_previous:
     :param forecast_latest:
+    :param npc_drop:
     :return:
     """
     this_time = datetime.utcfromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M')
     this_drop_decimal = quantity * price / 1e9
-    this_message = "{}: {} dropped {:,} shares at ${:,.2f} for a grand total of ${:,.1f}B".format(
-        this_time, name, quantity, price, this_drop_decimal)
+    npc = ''
+    if npc_drop:
+        npc = '*NPC* '
+    this_message = "{}: {}{} dropped {:,} shares at ${:,.2f} for a grand total of ${:,.1f}B".format(
+        this_time, npc, name, quantity, price, this_drop_decimal)
     if forecast_previous and forecast_latest:
         this_message = "{}: {} changed from {} to {} with {:,} shares available at ${:,.2f}".format(
             this_time, name, forecast_previous, forecast_latest, current_quantity, price)