def tetres_workzone_list(): wzgroup_id = request.form.get('wzgroup_id') wzDA = WorkZoneDataAccess() wz_list = wzDA.search([('wz_group_id', wzgroup_id)]) wzDA.close_session() return prot.response_success({'list': wz_list})
def find_workzones(prd): """ :type prd: pyticas.ttypes.Period :rtype: list[pyticas_tetres.ttypes.WorkZoneInfo] """ wzDA = WorkZoneDataAccess() data_list = wzDA.search_date_range(prd.start_date, prd.end_date) wzDA.close_session() return data_list
def _wz_insert_from_wz(wzi): """ :type wzi: WorkZoneInfo """ if not isinstance(wzi, WorkZoneInfo) or not wzi.route1 or not wzi.route2: return prot.response_invalid_request() wzDA = WorkZoneDataAccess() wzi.route1.name = 'route1 - %s' % wzi.route1.rnodes[0].corridor.name wzi.route1.desc = '' wzi.route2.name = 'route2 - %s' % wzi.route2.rnodes[0].corridor.name wzi.route2.desc = '' # wzi.id = wzDA.da_base.get_next_pk() try: wzi.workzone_length = route_length(wzi.route1) except: pass wzm = wzDA.insert(wzi) if wzm is False or not wzDA.commit(): return prot.response_fail('fail to save workzone route data (1)') wzi.id = wzm.id inserted_id = wzi.id tetres_api.add_actionlog(ActionLogDataAccess.INSERT, wzDA.get_tablename(), inserted_id, ActionLogDataAccess.data_description( ActionLogDataAccess.DT_WORKZONE, wzi), handled=False, dbsession=wzDA.get_session()) wzDA.close_session() return prot.response_success(obj=inserted_id)
def tetres_workzone_update(): wz_id = request.form.get('id') wz_json = request.form.get('data') wzDA = WorkZoneDataAccess() exWZObj = wzDA.get_by_id(wz_id) if not exWZObj: wzDA.close_session() return prot.response_invalid_request() info = json2wzi(wz_json) route2 = route.opposite_route(info.route1) cfg2 = info.route1.cfg.clone() rc.route_config.reverse(cfg2) route2.cfg = cfg2 info.route2 = route2 info.route1.name = 'route1 - %s' % info.route1.rnodes[0].corridor.name info.route1.desc = '' info.route2.name = 'route2 - %s' % info.route2.rnodes[0].corridor.name info.route2.desc = '' if not isinstance(info.route2, Route): wzDA.close_session() return prot.response_fail( 'fail to load_data route configuration file') wzgDA = WZGroupDataAccess(session=wzDA.get_session()) is_updated = wzDA.update(wz_id, info.get_dict()) if not is_updated or not wzDA.commit(): wzDA.rollback() wzDA.close_session() return prot.response_fail('fail to update database (1)') is_updated = wzgDA.update_years(exWZObj.wz_group_id) if not is_updated or not wzgDA.commit(): wzgDA.rollback() wzgDA.close_session() return prot.response_fail('fail to update database (2)') updatedWZObj = wzDA.get_by_id(wz_id) inserted = _wz_insert_feature(updatedWZObj) if not inserted: wzDA.close_session() return prot.response_fail('fail to update database (3)') # commit here # if not wzDA.commit(): # return prot.response_fail('fail to update database (4)') tetres_api.add_actionlog(ActionLogDataAccess.UPDATE, wzDA.get_tablename(), wz_id, ActionLogDataAccess.data_description( ActionLogDataAccess.DT_WORKZONE, updatedWZObj), handled=_should_be_set_as_handled( exWZObj, updatedWZObj), dbsession=wzDA.get_session()) wzDA.close_session() return prot.response_success(wz_id)
def tetres_workzone_list_all(): wzDA = WorkZoneDataAccess() wz_list = wzDA.list() wzDA.close_session() return prot.response_success({'list': wz_list})
def test_data(): import datetime from pyticas import route from pyticas_tetres.ttypes import WorkZoneInfo, WorkZoneGroupInfo, TTRouteInfo, SpecialEventInfo from pyticas_tetres.da.wz import WorkZoneDataAccess from pyticas_tetres.da.wz_group import WZGroupDataAccess from pyticas_tetres.da.specialevent import SpecialEventDataAccess from pyticas_tetres.da.route import TTRouteDataAccess # route data r1 = route.create_route('S38', 'S40', name='Route I-35W NB') # I-35W NB r2 = route.create_route('S186', 'S188', name='Route I-494 WB') # I-494 WB r3 = route.create_route('S428', 'S430', name='Route US-169 NB') # US169 NB ri1 = TTRouteInfo(r1) ri2 = TTRouteInfo(r2) ri3 = TTRouteInfo(r3) dsRoute = TTRouteDataAccess() dsWZ = WorkZoneDataAccess(session=dsRoute.da_base.session) dsWZGroup = WZGroupDataAccess(session=dsRoute.da_base.session) dsSE = SpecialEventDataAccess(session=dsRoute.da_base.session) rm = dsRoute.insert(ri1) rm = dsRoute.insert(ri2) rm = dsRoute.insert(ri3) # workzone data def _wzg(idx, r1, r2, y1, y2): wgi = WorkZoneGroupInfo() wgi.name = 'test wz group %d' % idx wgi.desc = 'test is test wz group %d' % idx wgi.years = WorkZoneGroupInfo.years_string(y1, y2) wgi.corridors = WorkZoneGroupInfo.corridor_string([r1, r2]) return wgi def _wzi(idx, r1, r2, y1, y2, wgid): wi = WorkZoneInfo() wi.wz_group_id = wgid wi.route1 = r1 wi.route2 = r2 wi.memo = 'memo of test wz %d' % idx sdt = datetime.datetime(y1, 3, 2, 1, 0, 0) edt = datetime.datetime(y2, 7, 2, 1, 0, 0) wi.start_time = sdt.strftime('%Y-%m-%d %H:%M:%S') wi.end_time = edt.strftime('%Y-%m-%d %H:%M:%S') wi.years = WorkZoneInfo.years_string(y1, y2) return wi r1 = route.create_route('S38', 'S40', name='Route I-35W NB') # I-35W NB r2 = route.opposite_route(r1) r3 = route.create_route('S186', 'S188', name='Route I-494 WB') # I-494 WB r4 = route.opposite_route(r3) wgi1 = _wzg(1, r1, r2, 2012, 2012) wgi2 = _wzg(2, r3, r4, 2012, 2013) wgi3 = _wzg(3, r1, r2, 2014, 2016) ac = True wgm1 = dsWZGroup.insert(wgi1) wgm2 = dsWZGroup.insert(wgi2) wgm3 = dsWZGroup.insert(wgi3) wi1 = _wzi(1, r1, r2, 2012, 2012, wgm1.id) wi2 = _wzi(2, r3, r4, 2012, 2013, wgm2.id) wi3 = _wzi(3, r1, r2, 2014, 2016, wgm3.id) wm1 = dsWZ.insert(wi1) wm2 = dsWZ.insert(wi2) wm3 = dsWZ.insert(wi3) # special event data def _sei(idx, y1, m1, d1, y2, m2, d2, att): sei = SpecialEventInfo() sei.name = 'test se %d' % idx sei.description = 'test is test se %d' % idx sdt = datetime.datetime(y1, m1, d1, 1, 0, 0) edt = datetime.datetime(y2, m2, d2, 1, 0, 0) sei.start_time = sei.datetime2str(sdt) sei.end_time = sei.datetime2str(edt) sei.set_years() sei.attendance = att sei.lon = -93.331893 sei.lat = 44.970797 return sei se1 = _sei(1, 2014, 3, 1, 2014, 3, 2, 1000) se2 = _sei(2, 2012, 4, 1, 2012, 4, 2, 20000) se3 = _sei(3, 2016, 5, 1, 2016, 5, 2, 300) sem1 = dsSE.insert(se1) sem2 = dsSE.insert(se2) sem3 = dsSE.insert(se3) dsWZ.close_session() dsSE.close_session() dsRoute.close_session()
def update_all_workzone_features(): from pyticas_tetres.da.wz import WorkZoneDataAccess da_wz = WorkZoneDataAccess() for wzi in da_wz.list(): wz_insert_feature(wzi)