def saveToHistory(updates): print("inhistory") rec = Historical_stock_prices() rec.stock_name = updates.stock_name rec.trading_date = updates.trading_date rec.closing_price = updates.closing_price rec.price_difference = updates.price_difference rec.up_or_down_circuit_indicator = updates.up_or_down_circuit_indicator rec.upper_price_circuit = updates.upper_price_circuit rec.lower_price_circuit = updates.lower_price_circuit rec.no_of_falls = updates.no_of_falls rec.no_of_rises = updates.no_of_falls rec.no_of_days_since_last_circuit = updates.no_of_days_since_last_circuit rec.save()
def index(request): with open('dmartOneYear.csv', 'r') as f: reader = csv.reader(f) entries = [] priceUpRecord = [] priceDownRecord = [] dateRecords = [] cnt = 1 nUps = 0 nDowns = 0 for i, row in enumerate(reader): isScripRecordPresent = Recently_Updated_Records.objects.filter( stock_name=row[0])[:1] # ignore title of column if (i == 0): print("wrong") pass elif (i == 1): rec = Historical_stock_prices() print(len(isScripRecordPresent)) row = " ".join(row) row = row.replace(";", " ") row = row.split() rec.stock_name = row[0] print("close" + row[2]) rec.trading_date = row[2] rec.closing_price = row[8] addRecordsToAll_Records_Table(rec) rec.price_difference = float(row[8]) * 0.05 rec.upper_price_circuit = (float(row[8]) * 0.05) + float( row[8]) rec.lower_price_circuit = float( row[8]) - (float(row[8]) * 0.05) rec.no_of_days_since_last_circuit = 0 rec.up_or_down_circuit_indicator = 'nil' priceUpRecord.insert(0, float(rec.upper_price_circuit)) priceDownRecord.insert(0, rec.lower_price_circuit) rec.no_of_rises = 0 rec.no_of_falls = 0 entries.append(rec) dateRecords.insert(0, rec.trading_date) print("executed") rec.save() if (len(isScripRecordPresent) == 0): TrackUpdates(rec) pass else: cnt += 1 rec = Historical_stock_prices() row = " ".join(row) row = row.replace(";", " ") row = row.split(" ") rec.stock_name = row[0] rec.trading_date = row[2] rec.closing_price = row[8] print("closingprice" + rec.closing_price) print(priceUpRecord[0]) # checking for lower price if (float(rec.closing_price) > float(priceUpRecord[0])): rec.price_difference = float(row[8]) * 0.05 rec.upper_price_circuit = (float(row[8]) * 0.05) + float( row[8]) priceUpRecord.insert(0, rec.upper_price_circuit) rec.lower_price_circuit = float( row[8]) - (float(row[8]) * 0.05) priceDownRecord.insert(0, rec.lower_price_circuit) nUps += 1 rec.no_of_days_since_last_circuit = dateDifference( dateRecords[0], rec.trading_date) dateRecords.insert(0, rec.trading_date) rec.up_or_down_circuit_indicator = 'Up' rec.no_of_rises = nUps rec.no_of_falls = nDowns addRecordsToAll_Records_Table(rec) rec.save() if (len(isScripRecordPresent) != 0): TrackUpdates(rec) # checking for upper price elif (float(rec.closing_price) < float(priceDownRecord[0])): rec.price_difference = float(row[8]) * 0.05 rec.lower_price_circuit = float( row[8]) - (float(row[8]) * 0.05) priceDownRecord.insert(0, rec.lower_price_circuit) rec.upper_price_circuit = (float(row[8]) * 0.05) + float( row[8]) priceUpRecord.insert(0, rec.upper_price_circuit) rec.no_of_days_since_last_circuit = dateDifference( dateRecords[0], rec.trading_date) dateRecords.insert(0, rec.trading_date) nDowns += 1 rec.up_or_down_circuit_indicator = 'Down' rec.no_of_rises = nUps rec.no_of_falls = nDowns addRecordsToAll_Records_Table(rec) rec.save() if (len(isScripRecordPresent) != 0): TrackUpdates(rec) else: rec.price_difference = " " rec.lower_price_circuit = " " rec.upper_price_circuit = " " rec.no_of_days_since_last_circuit = "" rec.no_of_falls = nDowns rec.no_of_rises = nUps addRecordsToAll_Records_Table(rec) entries.append(rec) return HttpResponse('<h1>basics</h1>')