Example #1
0
            csvWriter.writerow(['Time', 'Flow'])

            print flow.values[:1], flow.times[:1]
            print flow.values[-1], flow.times[-1]

            csvList = []

            for i in range(0, flow.numberValues):
                # print int(flow.times[i])
                time = HecTime()
                time.set(int(flow.times[i]))

                d = [
                    time.year(),
                    '%d' % (time.month(), ),
                    '%d' % (time.day(), )
                ]
                t = [
                    '%d' % (time.hour(), ),
                    '%d' % (time.minute(), ),
                    '%d' % (time.second(), )
                ]
                if (int(t[0]) > 23):
                    t[0] = '23'
                    dtStr = '-'.join(str(x) for x in d) + ' ' + ':'.join(
                        str(x) for x in t)
                    dt = datetime.datetime.strptime(dtStr, '%Y-%m-%d %H:%M:%S')
                    dt = dt + datetime.timedelta(hours=1)
                else:
                    dtStr = '-'.join(str(x) for x in d) + ' ' + ':'.join(
                        str(x) for x in t)
Example #2
0
            MessageBox.showError('No Data', 'Error')
        else :
            csvWriter.writerow(['Location Ids', 'Hanwella'])
            csvWriter.writerow(['Time', 'Flow'])

            print flow.values[:1], flow.times[:1]
            print flow.values[-1], flow.times[-1]

            csvList = []

            for i in range(0, flow.numberValues) :
                # print int(flow.times[i])
                time = HecTime()
                time.set(int(flow.times[i]))
                
                d = [time.year(), '%d' % (time.month(),), '%d' % (time.day(),)]
                t = ['%d' % (time.hour(),), '%d' % (time.minute(),), '%d' % (time.second(),)]
                if(int(t[0]) > 23) :
                    t[0] = '23'
                    dtStr = '-'.join(str(x) for x in d) + ' ' + ':'.join(str(x) for x in t)
                    dt = datetime.datetime.strptime(dtStr, '%Y-%m-%d %H:%M:%S')
                    dt = dt + datetime.timedelta(hours=1)
                else :
                    dtStr = '-'.join(str(x) for x in d) + ' ' + ':'.join(str(x) for x in t)
                    dt = datetime.datetime.strptime(dtStr, '%Y-%m-%d %H:%M:%S')

                csvList.append([dt.strftime('%Y-%m-%d %H:%M:%S'), "%.2f" % flow.values[i]])
                
            print csvList[:3], "...", csvList[-3:]
            csvWriter.writerows(csvList)
Example #3
0
    if tw != None:
        st, et = tw
        print("Time window: {}".format(tw))
    else:
        raise Exception('No forecast open on Modeling tab to get a timewindow.')
    st = HecTime(st, HecTime.MINUTE_GRANULARITY)
    st.showTimeAsBeginningOfDay(True)
    # Convert start to UTC
    print('Converting time window to UTC for API request.')
    ws_tz = cavistatus.get_timezone()
    HecTime.convertTimeZone(st, ws_tz, TimeZone.getTimeZone('UTC'))    
    et = HecTime(et, HecTime.MINUTE_GRANULARITY)
    et.showTimeAsBeginningOfDay(True)
    # Convert end to UTC
    HecTime.convertTimeZone(et, ws_tz, TimeZone.getTimeZone('UTC'))    
    after = '{}-{:02d}-{:02d}T{:02d}:{:02d}:00Z'.format(st.year(), st.month(), st.day(), st.hour(), st.minute())
    before = '{}-{:02d}-{:02d}T{:02d}:{:02d}:00Z'.format(et.year(), et.month(), et.day(), et.hour(), et.minute())    
    
    # DSS filename and path
    if dssfilename is None: dssfilename = 'data.dss'
    if not dssfilename.endswith('.dss'): dssfilename += '.dss'
    if dsspath is None: dsspath = cavistatus.get_database_directory()
    dsspath = os.path.expandvars(dsspath)
    # Join the path and
    dbdss = os.path.join(dsspath, dssfilename)
    print('DSS: {}'.format(dbdss))
    
    endpoint = re.sub(r':\w+', ws_name_slug, endpoint)
else:
    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
    # TESTING SECTION WHEN NOT RUNNING IN CAVI
    if (TS and hasattr(flow,'times')):
        pathArray=path.split('/')
        pathArray[4]=''
        parsepath='/'.join(pathArray)
        if (parsepath in visited):
            continue
        else:
            visited[parsepath]=True

        vs=[]

        try:
            for i in (range(len(flow.times))):
                t=HecTime()
                t.set(flow.times[i])
                date=str(t.year())+'-'+str(t.month())+'-'+str(t.day())
                val="%.3f}" % flow.values[i];            
                vs.append('""('+str(date)+','+val+')""')
        except :
            vs=[]

        v='"{'+','.join(vs)+'}"'
        st=HecTime()
        st.set(flow.startTime)
        sd=str(st.year())+'-'+str(st.month())+'-'+str(st.day())
        et=HecTime()
        et.set(flow.endTime)
        ed=str(et.year())+'-'+str(et.month())+'-'+str(et.day())
        parms=['"'+path+'"',
               sd,
               ed,