PADME Train Wiki
Train Selection
Search
Trains
SupplierRatingTest
855
main.py
Code fragments of main.py
import psycopg2
import os
import json
conn = psycopg2.connect(database=os.environ["DB_NAME"], user=os.environ["DATA_SOURCE_USERNAME"], host=os.environ["DATA_SOURCE_HOST"], password=os.environ["DATA_SOURCE_PASSWORD"], port=os.environ["DATA_SOURCE_PORT"] )
conn = psycopg2.connect(database=os.environ["DB_NAME"], user=os.environ["DATA_SOURCE_USERNAME"], host=os.environ["DATA_SOURCE_HOST"], password=os.environ["DATA_SOURCE_PASSWORD"], port=os.environ["DATA_SOURCE_PORT"] )
cursor = conn.cursor()
cursor.execute("SELECT * FROM supplier_ratings")
ratings = cursor.fetchall()
# entry: (1, 'Supplier 2448', 'GmbH', 'In time', 20, 6, 456)
cnt_in_time = sum(1 for x in ratings if x[3] == "In time")
score = (100/ len(ratings)) * cnt_in_time
res = {'score': round(score, 2)}
print(res)
result_file = 'result.json'
with open(result_file, 'w') as f:
json.dump(res, f)
with open(result_file, 'r', encoding='utf-8') as f:
file_content = f.read()
clean_score = file_content[file_content.find('{'):]
clean_score = clean_score.replace('\u0000', '')
with open(result_file, 'w', encoding='utf-8') as f:
json.dump(clean_score, f, ensure_ascii=False)
Graph
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
undefined
main.py
import psycopg2
None
import os
import json
conn = psycopg2.connect(database=os.environ["DB_NAME"], user=os.environ["DATA_SOURCE_USERNAME"], host=os.environ["DATA_SOURCE_HOST"], password=os.environ["DATA_SOURCE_PASSWORD"], port=os.environ["DATA_SOURCE_PORT"] )
cursor = conn.cursor()
cursor.execute("SELECT * FROM supplier_ratings")
ratings = cursor.fetchall()
# entry: (1, 'Supplier 2448', 'GmbH', 'In time', 20, 6, 456)
cnt_in_time = sum(1 for x in ratings if x[3] == "In time")
score = (100/ len(ratings)) * cnt_in_time
res = {'score': round(score, 2)}
print(res)
result_file = 'result.json'
with open(result_file, 'w') as f:
json.dump(res, f)
with open(result_file, 'r', encoding='utf-8') as f:
file_content = f.read()
clean_score = file_content[file_content.find('{'):]
clean_score = clean_score.replace('\u0000', '')
with open(result_file, 'w', encoding='utf-8') as f:
json.dump(clean_score, f, ensure_ascii=False)
Search
Train Selection