Skip to content

Commit

Permalink
Finish adding support for Indice filtering
Browse files Browse the repository at this point in the history
version 4.2 release ready
  • Loading branch information
virresh committed Jul 16, 2020
1 parent ac179d2 commit 4560e3b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 18 deletions.
50 changes: 34 additions & 16 deletions python_client/app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import datetime
import traceback
import webview
import collections.abc
from multiprocessing.managers import BaseManager

eventQ = queue.Queue(maxsize=100)
Expand Down Expand Up @@ -44,6 +45,14 @@ def getQ():
# g.eventQ = queue.Queue(maxsize=100)
return eventQ

def update(d, u):
for k, v in u.items():
if isinstance(v, collections.abc.Mapping):
d[k] = update(d.get(k, {}), v)
else:
d[k] = v
return d

def attachToStream():
while True:
item = getQ().get()
Expand Down Expand Up @@ -109,7 +118,7 @@ def process_fu(weblink, saveloc, d, asPrefix=False):
df.to_csv(saveloc, header=None, index=None)
return df

def process_in(weblink, saveloc, d, index_mapping={}):
def process_in(weblink, saveloc, d, index_mapping={}, keeplist=set(), keepall='false'):
df = get_csv(weblink)
df = df.replace('-', '0.0')

Expand All @@ -127,12 +136,17 @@ def process_in(weblink, saveloc, d, index_mapping={}):
df = df[['SYMBOL', 'DATE', 'OPEN', 'HIGH', 'LOW', 'CLOSE', 'VOLUME', 'OI']]
df['SYMBOL'] = df['SYMBOL'].apply(lambda x: x.upper())
def _rename(item):
if item in index_mapping and index_mapping[item] is not None:
if item in index_mapping and index_mapping[item] in keeplist:
return index_mapping[item]
else:
elif item in index_mapping and keepall != 'false':
return index_mapping[item]
elif keepall != 'false':
return item.replace('NIFTY', 'NSE').replace(' ', '')
else:
return None
# df['SYMBOL'] = df['SYMBOL'].apply(lambda x: x.replace(' ', '_'))
df['SYMBOL'] = df['SYMBOL'].apply(_rename)
df = df.dropna()
df.to_csv(saveloc, header=None, index=None)
return df

Expand Down Expand Up @@ -173,13 +187,23 @@ def process_day(configs, date):
inlocation = os.path.join(configs['SETTINGS']['inDir']['value'], parse(date, 'IN_{0:%Y}{0:%^b}{0:%d}.txt'))
if not os.path.exists(configs['SETTINGS']['inDir']['value']):
os.makedirs(configs['SETTINGS']['inDir']['value'], exist_ok=True)
indf = process_in(inlink, inlocation, date)

index_mapping = configs['index_map']
keeplist = set()

for key, val in index_mapping.items():
if configs['INDICES'][val]['value'] == 'true':
keeplist.add(val)

indf = process_in(inlink, inlocation, date, index_mapping, keeplist, configs['SETTINGS']['inKeepOthersCheck']['value'])
getQ().put({'event': 'log', 'data': parse(date, 'Converted Index Bhavcopy for {0:%Y}-{0:%b}-{0:%d}')})
except:
getQ().put({'event': 'log', 'data': parse(date, 'Cannot Find IN Bhavcopy for {0:%Y}-{0:%b}-{0:%d}')})

if configs['SETTINGS']['allCheck']['value'] == 'true' and not (eqdf is None and fudf is None and indf is None):
try:
if configs['SETTINGS']['allIncludeFUCheck']['value'] == 'false':
fudf = None
alllocation = os.path.join(configs['SETTINGS']['allDir']['value'], parse(date, 'ALL_{0:%Y}{0:%^b}{0:%d}.txt'))
alldf = pd.concat([eqdf, fudf, indf])
if not os.path.exists(configs['SETTINGS']['allDir']['value']):
Expand All @@ -203,15 +227,15 @@ def loadConfigFromDisk():
if os.path.exists('./generate_config.json'):
with open('./generate_config.json', 'r') as f:
aux_config = json.load(f)
main_config.update(aux_config)
main_config = update(main_config, aux_config)

states = main_config['INDICES']
defaultstate = main_config['SETTINGS']['inKeepOthersCheck']['value']
index_state_map = {}
for k, v in main_config['index_map'].items():
index_state_map[v] = {"type": "checkbox", "value": defaultstate}
if v in states:
index_state_map[v].update(states[v])
index_state_map[v] = update(index_state_map[v], states[v])

main_config['INDICES'] = index_state_map

Expand Down Expand Up @@ -245,13 +269,7 @@ def process_range():
getQ().put({'event': 'progress', 'data': '-1'})
return

with open(os.path.join(app.static_folder, 'default_config.json'), 'r') as f:
main_config = json.load(f)

if os.path.exists('./generate_config.json'):
with open('./generate_config.json', 'r') as f:
aux_config = json.load(f)
main_config.update(aux_config)
main_config = loadConfigFromDisk()

getQ().put({'event': 'progress', 'data': '0'})
delta = datetime.timedelta(1)
Expand Down Expand Up @@ -321,13 +339,13 @@ def saveConfig():
print(d)

if "BASELINK" in d:
main_config["BASELINK"].update(d["BASELINK"])
main_config["BASELINK"] = update(main_config["BASELINK"], d["BASELINK"])

if "LINKS" in d:
main_config["LINKS"].update(d["LINKS"])
main_config["LINKS"] = update(main_config["LINKS"], d["LINKS"])

if "index_map" in d:
main_config["index_map"].update(d["index_map"])
main_config["index_map"] = update(main_config["index_map"], d["index_map"])

saveConfigToDisk(main_config)

Expand Down
4 changes: 4 additions & 0 deletions python_client/app/static/default_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
"type": "checkbox",
"value": "true"
},
"allIncludeFUCheck": {
"type": "checkbox",
"value": "false"
},
"allDir": {
"type": "directory",
"value": "./EOD"
Expand Down
25 changes: 23 additions & 2 deletions python_client/app/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,14 @@ <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
</button>
</div>
<div class="modal-body">
<button class="btn btn-info" onclick="setAll('true', '#inFilterModal')">Check All</button>
<button class="btn btn-info" onclick="setAll('false', '#inFilterModal')">UnCheck All</button>
<div id="inFilterModal">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
<button type="button" class="btn btn-primary" onclick="submitForm('#preferencesForm')">Save changes</button>
</div>
</div>
</div>
Expand Down Expand Up @@ -163,6 +165,14 @@ <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<input type="hidden" value="false" name="allCheck" ><input type="checkbox" onclick="jankyCheckbox(this)" class="form-control booleancheck" id="allCheck">
</div>
</div>
<div class="form-group row">
<label for="allCheck" class="col-sm-4 col-form-label">Include Futures?</label>
<div class="col-sm-8">
<!-- <input type="hidden" value="false" name="allCheck"> -->
<input type="hidden" value="false" name="allIncludeFUCheck"><input type="checkbox" onclick="jankyCheckbox(this)"
class="form-control booleancheck" id="allIncludeFUCheck">
</div>
</div>
<div class="form-group row">
<label for="allDir" class="col-sm-4 col-form-label">Consolidation Directory:</label>
<div class="col-sm-6">
Expand Down Expand Up @@ -316,6 +326,15 @@ <h1 class="display-4">StockD v<span id="versionTxt">4.0</span></h1>
item.previousSibling.value = 'true';
}
};
function setAll(tvalue, parentId) {
event.preventDefault();
$(parentId + ' :input').each(function () {
if($(this).hasClass('booleancheck') && "" + $(this).prop('checked') != tvalue){
$(this).click();
console.log($(this));
}
});
};
function logListener(event) {
var theDiv = document.getElementById("logContainer");
var content = document.createTextNode(event.data);
Expand Down Expand Up @@ -380,11 +399,12 @@ <h1 class="display-4">StockD v<span id="versionTxt">4.0</span></h1>
await $.get('/getConfig').done(function (data) {

var inFilterModal = document.getElementById('inFilterModal');
inFilterModal.innerHTML = '';
var template = document.getElementById('mInFilterTemplate').innerHTML;
for(r in data['INDICES']){
var dataelem = {
lbl: r,
val: data['INDICES'][r]['value']
val: "false"
}
// console.log(dataelem);
// console.log(Mustache.render(template, dataelem))
Expand All @@ -398,6 +418,7 @@ <h1 class="display-4">StockD v<span id="versionTxt">4.0</span></h1>
else {
$('#' + r).click();
}
$('#' + r).val(data['INDICES'][r]['value']);
}


Expand Down

0 comments on commit 4560e3b

Please sign in to comment.