def position(request, date=None): """ display latest positions and overall """ view_control = ViewControl(date=date) overall, positions = view_control.get_json_data() parameters = {'overall': overall, 'mix_all': positions, 'date': view_control.date} return render(request, 'pms/position/view/index.html', parameters)
def setUp(self): for f, d in [(test_file, test_date), (test_file2, test_date2)]: oc = OpenCSV(f=f) position, overall = oc.get_symbol_lines() ip = ImportPosition(date=d, position=position, overall=overall) ip.save_overall() ip.save_position() del oc, ip #self.cv = ViewControl(date='2001-01-01') self.cv = ViewControl(date=test_date)
class TestViewControl(TestCase): def setUp(self): for f, d in [(test_file, test_date), (test_file2, test_date2)]: oc = OpenCSV(f=f) position, overall = oc.get_symbol_lines() ip = ImportPosition(date=d, position=position, overall=overall) ip.save_overall() ip.save_position() del oc, ip #self.cv = ViewControl(date='2001-01-01') self.cv = ViewControl(date=test_date) def tearDown(self): del self.cv def test_get_json_data(self): overall, positions = self.cv.get_json_data() print overall print positions overall, positions = self.cv.get_json_data() print overall print positions def test_subtract_one_day(self): from datetime import datetime, timedelta date = '2014-08-02' data_obj = datetime.strptime(date, '%Y-%m-%d') - timedelta(days=1) print date, data_obj self.assertEqual(data_obj.strftime('%Y-%m-%d'), '2014-08-01') def test_day_summary(self): #pl_open = self.cv.pl_open_summary() #for p in pl_open.keys(): # print p, pl_open[p] #pl_open_deep = self.cv.pl_open_deep_summary() #for p in pl_open_deep.keys(): # for d in pl_open_deep[p]: # print p, d, pl_open_deep[p][d] #pl_open, pl_day = self.cv.top3positions() #for p in pl_open.keys(): # print p, pl_open[p] #for p in pl_day.keys(): # print p, pl_day[p] columns = self.cv.instrument_describe() for c in columns.keys(): print c, columns[c]