Просмотр исходного кода

Conversion of Decimal.decimal to float

Foppe Hemminga 6 лет назад
Родитель
Сommit
34bcdaeac9
5 измененных файлов с 7 добавлено и 7 удалено
  1. 2 2
      database.py
  2. 1 1
      main.py
  3. 2 2
      model.py
  4. 1 1
      timestamp.txt
  5. 1 1
      view.py

+ 2 - 2
database.py

@@ -1,10 +1,10 @@
-# from dotenv import load_dotenv
+from dotenv import load_dotenv
 import os
 import os
 import psycopg2
 import psycopg2
 
 
 
 
 # Develop only
 # Develop only
-# load_dotenv()
+load_dotenv()
 
 
 host = os.environ["STOCK_DB_HOST"]
 host = os.environ["STOCK_DB_HOST"]
 port = os.environ["STOCK_DB_PORT"]
 port = os.environ["STOCK_DB_PORT"]

+ 1 - 1
main.py

@@ -25,7 +25,7 @@ if __name__ == '__main__':
         data_latest = model.get_data(stock_id, timestamp_latest, db)
         data_latest = model.get_data(stock_id, timestamp_latest, db)
         threshold = stock[3]
         threshold = stock[3]
         is_drop = model.process_data(data_previous, data_latest, threshold)
         is_drop = model.process_data(data_previous, data_latest, threshold)
-        current_price = data_latest.current_price
+        current_price = float(data_latest.current_price)
         quantity = data_latest.available_shares - data_previous.available_shares
         quantity = data_latest.available_shares - data_previous.available_shares
         stock_name = stock[0]
         stock_name = stock[0]
         message = view.create_message(
         message = view.create_message(

+ 2 - 2
model.py

@@ -71,8 +71,8 @@ def process_data(this_data_previous, this_data_latest, this_threshold):
     :return boolean:
     :return boolean:
     """
     """
     this_drop = False
     this_drop = False
-    quantity_previous = this_data_previous.available_shares * this_data_latest.current_price
-    quantity_latest = this_data_latest.available_shares * this_data_latest.current_price
+    quantity_previous = this_data_previous.available_shares * float(this_data_latest.current_price)
+    quantity_latest = this_data_latest.available_shares * float(this_data_latest.current_price)
     if quantity_latest - quantity_previous > this_threshold * 1e9:
     if quantity_latest - quantity_previous > this_threshold * 1e9:
         this_drop = True
         this_drop = True
     return this_drop
     return this_drop

+ 1 - 1
timestamp.txt

@@ -1 +1 @@
-1559608500
+1559654400

+ 1 - 1
view.py

@@ -13,7 +13,7 @@ def create_message(name, timestamp, price, quantity):
     :return:
     :return:
     """
     """
     this_time = datetime.utcfromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S')
     this_time = datetime.utcfromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S')
-    this_drop_decimal = float((quantity * 1.0) * (price * 1.0) / 1e9)
+    this_drop_decimal = quantity * price / 1e9
     this_message = "{}: {} dropped {} shares at ${:.2f} for a grand total of ${:.1f}B".format(
     this_message = "{}: {} dropped {} shares at ${:.2f} for a grand total of ${:.1f}B".format(
         this_time, name, quantity, price, this_drop_decimal)
         this_time, name, quantity, price, this_drop_decimal)
     return this_message
     return this_message