Skip to content

Commit 1cd5dbf

Browse files
committed
DLE-190519-Impl cmd app with build app run file
1 parent 88ec8eb commit 1cd5dbf

16 files changed

+438
-118
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
__pycache__
2+
.vscode/settings.json
3+
temp
4+
*.pkl

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"python.pythonPath": "C:\\Program Files (x86)\\Python37-32\\python.exe"
2+
"python.pythonPath": "Z:\\Program Files (x86)\\Python\\Python 3.7.2\\python.exe"
33
}

ExchangeRatesPrediction.spec

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# -*- mode: python -*-
2+
3+
block_cipher = None
4+
5+
added_files = [
6+
('config.json', '.'), # Loads the '' file from your root folder and outputs it with the same name on the same place.
7+
]
8+
9+
a = Analysis(['__main__.py'],
10+
pathex=['Z:\\WorkDev\\GitHub Repository\\TestOnSolve'],
11+
binaries=[],
12+
datas=[],
13+
hiddenimports=[],
14+
hookspath=[],
15+
runtime_hooks=[],
16+
excludes=[],
17+
win_no_prefer_redirects=False,
18+
win_private_assemblies=False,
19+
cipher=block_cipher,
20+
noarchive=False)
21+
pyz = PYZ(a.pure, a.zipped_data,
22+
cipher=block_cipher)
23+
exe = EXE(pyz,
24+
a.scripts,
25+
a.binaries,
26+
a.zipfiles,
27+
a.datas,
28+
[],
29+
name='ExchangeRatesPrediction',
30+
debug=False,
31+
bootloader_ignore_signals=False,
32+
strip=False,
33+
upx=True,
34+
runtime_tmpdir=None,
35+
console=True )

__main__.py

Lines changed: 90 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,116 @@
11
import sys
22
import os
3+
import datetime
34

45

56
ROOT_DIR = os.getcwd() # Get root directory
67
sys.path.append(os.path.dirname(ROOT_DIR + r'/'))# Add absolute path to current sys.path
78
# print('Path: ' + str(sys.path))
89

10+
from config import Configuration
11+
12+
from service.banking.exchangerate_service import ExchangeRateService
913

1014
"""
1115
doc: Main base class
1216
"""
1317
class Main():
1418

1519
def __init__(self):
16-
pass
20+
self.ApiGetExcRateConfig = Configuration().getApiConfig("get_exchangerate")
21+
self.ApiGetCurrencyConfig = Configuration().getApiConfig("get_currency")
22+
1723

1824
def mainProcess(self):
1925

2026
try:
21-
pass
27+
28+
print("Welcome to Exchange Rates Service!")
29+
option = input("Which services do you want to use?: \
30+
\n1. Predict tight range of matching (Quick process) \
31+
\n2. Predict wide range of matching (Long process) \
32+
\n3. Check exchange rates of specific currency \
33+
\n4. Check all exchange rates \
34+
\nAny key to quit... \
35+
\nPlease input your choice's number: ").strip()
36+
37+
38+
while ( option.isdigit() and int(option) > 0 and int(option) < 5 ):
39+
option = int(option)
40+
41+
checkedDate = input("Which date do you want to check? (YYYY-MM-DD): ").strip()
42+
baseCurrency = input("From currency (Code ISO 4217): ").strip()
43+
toCurrency = ''
44+
45+
if(option == 1):
46+
self.validateInput(option, checkedDate, baseCurrency, toCurrency)
47+
48+
service = ExchangeRateService()
49+
data = service.predicted_quick_exrate(self.ApiGetExcRateConfig, self.checkedDate, self.baseCurrency, self.toCurrency)
50+
service.display_graph(data)
51+
52+
elif(option == 2):
53+
self.validateInput(option, checkedDate, baseCurrency, toCurrency)
54+
checkedDaysPerMonth = 10
55+
56+
service = ExchangeRateService()
57+
data = service.predicted_long_exrate(self.ApiGetExcRateConfig, self.checkedDate, self.baseCurrency, self.toCurrency, checkedDaysPerMonth)
58+
service.display_graph(data)
59+
60+
elif(option == 3):
61+
self.validateInput(option, checkedDate, baseCurrency, toCurrency)
62+
63+
service = ExchangeRateService()
64+
data = service.get_specific_exrate_byDate(self.ApiGetExcRateConfig, self.checkedDate, self.baseCurrency, self.toCurrency)
65+
print(str(data.Currency) + " - " + str(data.RateValue))
66+
67+
elif(option == 4):
68+
self.validateInput(option, checkedDate, baseCurrency, toCurrency)
69+
70+
service = ExchangeRateService()
71+
data = service.get_exrate_byDate(self.ApiGetExcRateConfig, self.checkedDate, self.baseCurrency)
72+
print("\n".join([str(m.Currency) + " - " + str(m.RateValue) for m in data]))
73+
74+
else:
75+
pass
76+
77+
print("-"*30 + "PROCESS DONE" + "-"*30)
78+
79+
option = input("Which services do you want to use?: \
80+
\n1. Predict tight range of matching (Quick process) \
81+
\n2. Predict wide range of matching (Long process) \
82+
\n3. Check exchange rates of specific currency \
83+
\n4. Check all exchange rates \
84+
\nAny key to quit... \
85+
\nPlease input your choice's number: ").strip()
2286

2387
except Exception as ex:
2488
print('Error: ', ex)
2589

2690
print('#'*40)
2791
return
2892

93+
def validateInput(self, option, checkedDate, baseCurrency, toCurrency):
94+
self.baseCurrency = (not baseCurrency) and 'USD' or str(baseCurrency).upper()
95+
96+
currentDate = datetime.date.today()
97+
if ExchangeRateService().UtilCommon().validateDateFormat(checkedDate):
98+
checkedDate = ExchangeRateService().UtilCommon().parseStringToDateTime(checkedDate).date()
99+
self.checkedDate = (checkedDate >= currentDate) and currentDate or checkedDate
100+
else:
101+
self.checkedDate = currentDate
102+
103+
if(option == 1 or option == 2 or option == 3):
104+
self.toCurrency = toCurrency
105+
countFail = 0
106+
while not toCurrency:
107+
if countFail > 0:
108+
print("###Error: No data for To Currency")
109+
toCurrency = input("To currency (Code ISO 4217): ").strip()
110+
self.toCurrency = str(toCurrency).upper()
111+
countFail += 1
112+
113+
29114
"""
30115
doc: Code will begin from here
31116
"""
@@ -37,5 +122,6 @@ def mainProcess(self):
37122

38123
### BUILD APP
39124
# Step 1: Put all images folder to "dist" folder (folder to deploy app)
40-
# Step 2: Open CMD/Terminal and change directory path to main.py
41-
# Step 3: Run command => pyinstaller main.py
125+
# Step 2: Open CMD/Terminal and change directory path to main python script
126+
# Step 3: Run command in first time => pyinstaller --clean --distpath=./app_build --workpath=./temp --onefile --name ExchangeRatesPrediction ./__main__.py
127+
# Or Run this command when already have .spec file => pyinstaller --clean --distpath=./app_build --workpath=./temp --add-data="config.json;." --add-data="/model_trained/linear_model.pkl;." --onefile ExchangeRatesPrediction.spec

app_build/ExchangeRatesPrediction.exe

65 MB
Binary file not shown.

app_build/config.json

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"version": "1.0",
3+
"configurations":[
4+
{
5+
"type": "project_info",
6+
"project_name": "Test_OnSolve"
7+
},
8+
{
9+
"type": "api",
10+
"site_name": "openexchangerates",
11+
"api_type": "get_exchangerate",
12+
"api_host": "https://openexchangerates.org",
13+
"api_path": "/api/historical/",
14+
"api_extension": ".json",
15+
"api_queries": [
16+
{
17+
"param_name": "app_id",
18+
"param_defvalue": "e1e21981345b4bbe959f49186802ce97"
19+
},
20+
{
21+
"param_name": "base",
22+
"param_defvalue": "USD"
23+
}
24+
],
25+
"is_using": "False"
26+
},
27+
{
28+
"type": "api",
29+
"site_name": "exchangeratesapi",
30+
"api_type": "get_exchangerate",
31+
"api_host": "https://api.exchangeratesapi.io",
32+
"api_path": "/",
33+
"api_extension": "",
34+
"api_queries": [
35+
{
36+
"param_name": "base",
37+
"param_defvalue": "USD"
38+
}
39+
],
40+
"is_using": "True"
41+
},
42+
{
43+
"type": "api",
44+
"site_name": "openexchangerates",
45+
"api_type": "get_currency",
46+
"api_host": "https://openexchangerates.org",
47+
"api_path": "/api/currencies",
48+
"api_extension": ".json",
49+
"api_queries": [],
50+
"is_using": "True"
51+
}
52+
]
53+
}

config.json

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,47 @@
77
},
88
{
99
"type": "api",
10-
"api_name": "openexchangerates_exchange_rates",
11-
"site_name": "openexchangerates",
12-
"site_domain": "https://openexchangerates.org",
13-
"api_url": "/api/historical/",
10+
"site_name": "openexchangerates",
11+
"api_type": "get_exchangerate",
12+
"api_host": "https://openexchangerates.org",
13+
"api_path": "/api/historical/",
1414
"api_extension": ".json",
15-
"api_params": [
15+
"api_queries": [
1616
{
1717
"param_name": "app_id",
18-
"default_value": "e1e21981345b4bbe959f49186802ce97"
18+
"param_defvalue": "e1e21981345b4bbe959f49186802ce97"
1919
},
2020
{
2121
"param_name": "base",
22-
"default_value": "USD"
22+
"param_defvalue": "USD"
2323
}
24-
]
24+
],
25+
"is_using": "False"
2526
},
2627
{
2728
"type": "api",
28-
"api_name": "exchangeratesapi_exchange_rates",
29-
"site_name": "exchangeratesapi",
30-
"site_domain": "https://api.exchangeratesapi.io",
31-
"api_url": "/",
32-
"api_extension": ".json",
33-
"api_params": [
29+
"site_name": "exchangeratesapi",
30+
"api_type": "get_exchangerate",
31+
"api_host": "https://api.exchangeratesapi.io",
32+
"api_path": "/",
33+
"api_extension": "",
34+
"api_queries": [
3435
{
3536
"param_name": "base",
36-
"default_value": "USD"
37+
"param_defvalue": "USD"
3738
}
38-
]
39+
],
40+
"is_using": "True"
41+
},
42+
{
43+
"type": "api",
44+
"site_name": "openexchangerates",
45+
"api_type": "get_currency",
46+
"api_host": "https://openexchangerates.org",
47+
"api_path": "/api/currencies",
48+
"api_extension": ".json",
49+
"api_queries": [],
50+
"is_using": "True"
3951
}
4052
]
4153
}

config.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def __init__(self):
1717
self.Platform = self.getOSplatform()
1818
self.domain_factory = DomainFactory()
1919
self.ConfigApiModel = self.domain_factory.init_ModelClass('ConfigApiModel')
20+
self.ConfigApiQueryModel = self.domain_factory.init_ModelClass('ConfigApiQueryModel')
2021

2122

2223
def getOSplatform(self):
@@ -32,24 +33,48 @@ def getOSplatform(self):
3233
return os
3334

3435

35-
def getApiConfig(self, apiName):
36-
36+
def getApiConfig(self, apiType):
3737
try:
38-
if apiName:
38+
if apiType:
3939

4040
with open(self.ConfigFilePath, 'rt') as config_file:
4141
config = json.load(config_file)
4242
# print(config)
4343
for cf in list(config['configurations']):
44-
if(cf['type'] == "api" and cf['api_name'] == apiName):
44+
if(cf['type'] == "api" and cf['api_type'] == apiType and cf['is_using'] == "True"):
4545
modelApiConfig = self.domain_factory.map_JsonToDomainClass(self.ConfigApiModel, cf)
4646
return modelApiConfig
4747

4848
except Exception as ex:
4949
print('Error: ', ex)
5050

51+
return
52+
53+
54+
def initApiQueryString(self, config, lstParamModel):
55+
if config:
56+
lstApiParam = self.domain_factory.map_ListJsonToListDomainClass(self.ConfigApiQueryModel, config.api_queries)
57+
apiStr = ""
58+
for idx, para in enumerate(lstApiParam):
59+
actual_value = para.param_defvalue
60+
if lstParamModel and len(lstParamModel) > 0:
61+
pr = [pr for pr in lstParamModel if pr.param_name == para.param_name]
62+
if pr:
63+
actual_value = pr[0].param_curvalue
64+
singleParam = "{0}={1}".format(para.param_name, actual_value)
65+
if(idx == 0):
66+
apiStr = singleParam
67+
continue
68+
apiStr += "&" + singleParam
69+
return apiStr
5170
return None
5271

72+
73+
def initApiUrl(self, config, customPath, lstParamModel):
74+
if config:
75+
apiUrl = "{0}{1}{2}{3}?{4}".format(config.api_host, config.api_path, customPath, config.api_extension, self.initApiQueryString(config, lstParamModel))
76+
return apiUrl
77+
return None
5378

5479

5580

0 commit comments

Comments
 (0)