def Get_TStoExport(exportSpreadsheetPath, startExportDate, endExportDate): """ <Script> <Author>admin</Author> <Description>Paradis perdu</Description> <Parameters> <Parameter name="exportSpreadsheetPath" type="string">spreadsheet_full_path</Parameter> <Parameter name="startExportDate" type="string">Time of the start export</Parameter> <Parameter name="endExportDate" type="string">Time of the end export.</Parameter> </Parameters> <ReturnValue type="Dictionary[string, List[data]]" >time series to export </ReturnValue> </Script> """ exportInfoList = LoadExportSpreadsheet(exportSpreadsheetPath); exportData = {} timeSeriesManager = app.Modules.Get('Time series Manager'); if timeSeriesManager == None: raise Exception('Can''t obtain a reference to Time series Manager.'); for exportInfo in exportInfoList: print 'fichier exporté =', exportInfo.TsToExport; print 'dossier MIKE Opération =',exportInfo.OutputPath; start = DateTime.ParseExact(startExportDate, 'MM/dd/yyyy HH:mm:ss', CultureInfo.InvariantCulture); end = DateTime.ParseExact(endExportDate, 'MM/dd/yyyy HH:mm:ss', CultureInfo.InvariantCulture); count = 1; for exportInfo in exportInfoList: ts = timeSeriesManager.TimeSeriesList.Fetch(exportInfo.TsToExport); exportData = ts.GetAll(); if (ts == None): message = 'Time series ' + exportInfo.TsPath + ' must be created before import.'; WriteError(message); tsMgr = app.Modules.Get('Time series Manager') outputPath =exportInfo.OutputPath; stationId = exportInfo.StationCode; type=exportInfo.Type; timeOfSimulationRun = start; firstTimeStep = startExportDate; lastTimeStep = endExportDate; if count <2: WriteExportTs(ts, outputPath, stationId, type, timeOfSimulationRun,firstTimeStep, lastTimeStep); count += 1; WriteExportTs_2(ts, outputPath, stationId, type, timeOfSimulationRun,firstTimeStep, lastTimeStep,startExportDate, endExportDate);
def HandlBtnClick(sender, e): try: url = None # button for changing session-stored location was pressed if sender.ID == 'btn_select_slct_loctn': countryCode = tool.ui.getCtrl('sel_country').SelectedValue cityIdentifier = tool.ui.getCtrl('txbx_city').Text lcDfnr.setLocByInpt(countryCode, cityIdentifier) if lcDfnr.getValidLoctn() is None: tool.errorMessage( ' <br />Es wurde keine Stadt oder Postleitzahl gefunden! <br />Hast du das richtige Land ausgewählt?<br />' ) return # go to data-projector elif 'btn_show_loctn_map' in sender.ID: url = WebConfigurationManager.AppSettings[ "debateMap"] # go to the map on 'openMap' elif 'btn_show_loctn_list' in sender.ID: url = WebConfigurationManager.AppSettings[ "debateProjector"] # go to the list with all infos on 'openList' # buil URL-parameter for data-filtering param = '?' + lcDfnr.getLoctnPrmtr() #http://localhost:3463/njb_2/projector_DebateMap.aspx?SliceActive=0&CrsCmd=&ResultLength=2500&ItemType=map&Loc=DE,&City=erkelenz&StartDate=2013-11-23&EndDate=2013-11-30&SrchMd=OR&Tags=,hashtagtest& #&StartDate=2013-11-23 #&EndDate=2013-11-30 strtTime = tool.ui.getCtrl('txbx_timeFrom').Text.strip() endTime = tool.ui.getCtrl('txbx_timeTo').Text.strip() if len(strtTime) > 0: startDt = DateTime.ParseExact(strtTime, "dd.MM.yyyy", CultureInfo.InvariantCulture) param += '&StartDate=' + startDt.ToString('yyyy-MM-dd') if len(endTime) > 0: endDt = DateTime.ParseExact(endTime, "dd.MM.yyyy", CultureInfo.InvariantCulture) param += '&EndDate=' + endDt.ToString('yyyy-MM-dd') # param = Page.Server.UrlEncode( param ) url += param tool.log.w2lgDvlp('search_rubric_handle_button . Url Param : ' + param) except Exception, e: tool.log.w2lgError(traceback.format_exc()) return
def WriteExportTs_2(ts, outputPath, stationId, type, timeOfSimulationRun,firstTimeStep, lastTimeStep, startExportDate, endExportDate): """ <Script> <Author>admin</Author> <Description>Saves a time series to a txt file.</Description> <Parameters> <Parameter name="ts" type="IDataSeries">Time series to export.</Parameter> <Parameter name="outputPath" type="string">The full path to the CSV file.</Parameter> <Parameter name="stationId" type="string">The id of the forecast station.</Parameter> <Parameter name="type" type="string">The name of the forecast station.</Parameter> <Parameter name="timeOfSimulationRun" type="datetime">The datetime of the simulation run.</Parameter> <Parameter name="firstTimeStep" type="datetime">DateTime of the start export.</Parameter> <Parameter name="lastTimeStep" type="datetime">DateTime of the end export.</Parameter> <Parameter name="startExportDate" type="string">Time of the start export</Parameter> <Parameter name="endExportDate" type="string">Time of the end export.</Parameter> </Parameters> </Script> """ fileName = 'Export'+ '.txt'; # Create new file and overwrite if it already exists. strBuilder = System.Text.StringBuilder(); currentDateTimeString = timeOfSimulationRun.ToString('yyyyMMddHHmm'); ExportDateTimeString = System.DateTime.Now. ToString('yyyyMMddHHmm'); start = DateTime.ParseExact(startExportDate, 'MM/dd/yyyy HH:mm:ss', CultureInfo.InvariantCulture); end = DateTime.ParseExact(endExportDate, 'MM/dd/yyyy HH:mm:ss', CultureInfo.InvariantCulture); #Write each time step. timeSteps = ts.GetAll(); for timeStep in timeSteps: if timeStep.XValue > start and timeStep.XValue < end: valueString = None; if (timeStep.YValue <> None): valueString = timeStep.YValue.ToString(System.Globalization.CultureInfo.InvariantCulture); if type == 'debit': timeStepString = System.String.Format('{0};{1};{2};{3};{4};{5};{6}', 'CQT', stationId, timeStep.XValue.ToString('yyyyMMdd'),timeStep.XValue.ToString('HHmm'), valueString, '2', '9'); strBuilder.AppendLine(timeStepString); else: timeStepString = System.String.Format('{0};{1};{2};{3};{4};{5};{6}', 'NGF', stationId, timeStep.XValue.ToString('yyyyMMdd'),timeStep.XValue.ToString('HHmm'), valueString, '2', '9'); strBuilder.AppendLine(timeStepString); FileName = System.IO.Path.Combine(outputPath, fileName); System.IO.File.AppendAllText(FileName, strBuilder.ToString()); return;
def GetDateTimeUtcFromISO8601FormattedDate(isoFormattedDate): return DateTime.ParseExact( isoFormattedDate, ISO8601_FORMAT_UTC, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal )
def ImportTimeseriesFromTextFile(): """ <Script> <Author>AUG</Author> <Description>This script imports timeseries from text files.</Description> </Script> """ # Set parameters folderPath = 'C:\\Data' # the folder where the files to import are located targetTimeseriesGroupName = '/Output' # the group where the timeseries will be created / updated datetimeFormat = "dd.MM.yyyy HH:mm" # tge date time format fileExtention="*.txt" # the extention of the input files variable = "Rainfall Depth" # the variable type valueType = DataSeriesValueType.Step_Accumulated # the value type firstLine = 11 # the first line with value (start at zero. 11 means 12th line) valueLength = 3 # the number of characters describing the value (e.g. "0.2" -> 3 characters, "11.248" -> 6 characters) # Set variables count = 0 tmgr = app.Modules.Get('Time series Manager'); # import files = Directory.GetFiles(folderPath, fileExtention, SearchOption.AllDirectories) group = tmgr.TimeSeriesGroupList.Fetch(targetTimeseriesGroupName) if group == None: group = tmgr.TimeSeriesGroupList.CreateNew(targetTimeseriesGroupName) tmgr.TimeSeriesGroupList.Add(group) for file in files: filename = Path.GetFileNameWithoutExtension(file) ts = tmgr.TimeSeriesList.Fetch(targetTimeseriesGroupName + "/" + filename) if ts == None: ts = tmgr.TimeSeriesList.CreateNew() ts.Name = filename ts.YAxisVariable = variable ts.ValueType = valueType ts.GroupId = group.Id tmgr.TimeSeriesList.Add(ts) lastTimestep = DateTime.MinValue else: timestepts = ts.FetchAll() if(timestepts.Count > 0): lastTimestep = timestepts[timestepts.Count - 1].XValue else: lastTimestep = DateTime.MinValue lines = File.ReadAllLines(file); for line in lines: if count >= firstLine: date = DateTime.ParseExact(line[0:datetimeFormat.Length], datetimeFormat, CultureInfo.InvariantCulture) if date > lastTimestep: value = float(line[-valueLength:]) step = ts.CreateNew() step.XValue = date step.YValue = value ts.Add(step) count+=1 tmgr.TimeSeriesList.Update(ts)
def setdate() : today = DateTime.Today dl = datetime(today.AddMonths(-2).Year,today.AddMonths(-2).Month,1) dh = datetime(today.AddMonths(-1).Year,today.AddMonths(-1).Month,1) # Stripping out the time segment and setting the document properties for Display #Document.Properties["dl"] = (DateTime.ParseExact(dl.strftime('%d/%m/%Y'),'dd/MM/yyyy',CultureInfo.InvariantCulture)).ToString().Substring(0,10) #Document.Properties["dh"] = (DateTime.ParseExact(dh.strftime('%d/%m/%Y'),'dd/MM/yyyy',CultureInfo.InvariantCulture)).ToString().Substring(0,10) #Document.Properties["dl"] = dl.ToString().Substring(0,10) #Document.Properties["dh"] = dh.ToString().Substring(0,10) Document.Properties["dl"] = dl.date().strftime('%m/%d/%Y') HighLabel = dh + timedelta (days = -1) Document.Properties["dh"] = HighLabel.date().strftime('%m/%d/%Y') myPanel = Document.ActivePageReference.FilterPanel myFilter = myPanel.TableGroups[0].GetFilter("Scan Date") lblFilter = myFilter.FilterReference.As[RangeFilter]() lblFilter.ValueRange = ValueRange(DateTime.ParseExact(dl.strftime('%m/%d/%Y'),'MM/dd/yyyy',CultureInfo.InvariantCulture),DateTime.ParseExact(dh.strftime('%m/%d/%Y'),'MM/dd/yyyy',CultureInfo.InvariantCulture))
def RunICM(Adapter): """ <Script> <Author>ANK</Author> <Description>run an ICM model</Description> <Parameters> <Parameter name="Adapter" type="IRuntimeAdapter">handle to the adapter</Parameter> </Parameters> </Script> """ tsMgr = app.Modules.Get("Time series Manager") # get the adapter root folder rootfolder = Adapter.RootFolderPath # convert dfs0-input files to Dummy_Inflow.csv # open dummy inflow and read all lines inflowPath = Path.Combine(rootfolder, "MODEL_SETUP\\import\\Dummy Inflow.csv") inflowLines = File.ReadAllLines(inflowPath) # read dfs0-files one by one l=8 tslist = [] while inflowLines[l].split(",")[0]!="P_DATETIME" : tsname = inflowLines[l].split(",")[0] tsFile = Path.Combine(rootfolder, "INPUT_DATA", tsname+".dfs0") tslist.extend(TsUtilities.ReadFromDFS0(tsMgr, tsFile)) l = l + 1; # make new lines newLines = [] i=0 while True: if i==6: # replace startdate line = tslist[0].Start.ToString("dd/MM/yyyy HH:mm:ss") + inflowLines[i][19:] else: line = inflowLines[i] newLines.append(line) if inflowLines[i].split(",")[0]=="P_DATETIME" : break; i = i + 1; # continue with timesteps for t in range(tslist[0].Count): line = tslist[0].Get(t).XValue.ToString("dd/MM/yyyy HH:mm:ss") for ds in tslist: line += "," + ds.Get(t).YValue.ToString(CultureInfo.InvariantCulture) newLines.append(line) # rewrite the input file File.WriteAllLines(inflowPath, newLines) # run the adapter bat-file startInfo = ProcessStartInfo() startInfo.CreateNoWindow = False; startInfo.UseShellExecute = False; startInfo.FileName = Path.Combine(rootfolder, "MODEL_SETUP", "run.bat"); startInfo.WorkingDirectory = Path.Combine(rootfolder, "MODEL_SETUP") with Process.Start(startInfo) as exeProcess : exeProcess.WaitForExit(); # convert exported csv-files to dfs0 # convert node depths dslist = [] for fil in Directory.GetFiles(Path.Combine(rootfolder,"MODEL_SETUP\\export"),"Node_*_depnod.csv"): lines = File.ReadAllLines(fil) headers = lines[0].split(",") for h in headers[2:]: ds = tsMgr.TimeSeriesList.CreateNew() ds.Name = h.strip() ds.YAxisVariable = "Water Level" dslist.append(ds) for line in lines[1:] : if not "[" in line: values = line.split(",") t = DateTime.ParseExact(values[0].strip(),"dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture) for v in range(2,values.Count): ds = dslist[v-2] vp = ds.CreateNew() vp.XValue = t vp.YValue = Double.Parse(values[v].strip(), CultureInfo.InvariantCulture) ds.Add(vp) # save to dfs0 for ds in dslist: fil = Path.Combine(rootfolder,"OUTPUT_DATA",ds.Name+".dfs0") TsUtilities.ExportToDfs0(ds,fil)
def ExecuteValidation(validationSpreadsheetPath, tOF, hindcast, forecast, logFilePath): """ <Script> <Author>KTH</Author> <Description>Executes the time series validation according to the validation spreadsheet specified.</Description> <Parameters> <Parameter name="validationSpreadsheetPath" type="string">Path to the spreadsheet</Parameter> <Parameter name="tOF" type="string">Time of Forecast for simulation</Parameter> <Parameter name="hindcast" type="int">Hindcast period in day.</Parameter> <Parameter name="forecast" type="int">Forecast period in day.</Parameter> <Parameter name="logFilePath" type="string">Path where the log file importLog.txt should be written.</Parameter> </Parameters> </Script> """ fileName = 'ValidationLog_' + System.DateTime.Now.ToString( 'yyyy-MM-dd_HH-mm-ss') + '.txt' global logFileName logFileName = System.IO.Path.Combine(logFilePath, fileName) validationInfoList = LoadValidationSpreadsheet(validationSpreadsheetPath) timeSeriesManager = app.Modules.Get('Time series Manager') if timeSeriesManager == None: raise Exception('Can' 't obtain a reference to Time series Manager.') tof = DateTime.ParseExact(tOF, 'MM/dd/yyyy HH:mm:ss', CultureInfo.InvariantCulture) for validationInfo in validationInfoList: ts = timeSeriesManager.TimeSeriesList.Fetch(validationInfo.TsPath) print validationInfo.TsOutputPath if (ts == None): message = 'Time series ' + validationInfo.TsPath + ' must be created before import.' WriteError(message) else: periodOption = PeriodOption.Entire_timeseries replaceOption = ReplaceOption.Replace_all_hits startDate = System.DateTime.MinValue endDate = System.DateTime.MaxValue startValidationDate = tof.AddDays(-hindcast) endValidationDate = tof.AddDays(forecast) if (startValidationDate <> None and endValidationDate <> None): if type(startValidationDate) is System.DateTime: startDate = tof.AddDays(-hindcast) else: startDate = System.DateTime.ParseExact( tof.AddDays(-hindcast), 'MM/dd/yyyy HH:mm:ss', System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None) #Convert dates from String format to DateTime format if type(endValidationDate) is System.DateTime: endDate = tof.AddDays(forecast) else: endDate = System.DateTime.ParseExact( tof.AddDays(forecast), 'MM/dd/yyyy HH:mm:ss', System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None) periodOption = PeriodOption.Sub_period rangeOption = RangeOption.Replace_outside_range rangeMax = 0 rangeMin = 0 maxGapUnit = MaxGapUnit.Hours maxGap = 1 replaceByValueForExceededRate = None replaceByValue = None replaceValue = 0 maxRateOfChange = 0 rateOfChangeOption = RateOfChangeOption.With_constant rateOfChangeUnit = ReplaceTool_RateOfChangeUnit.Per_hour # Change input time series or copy. if (validationInfo.TsOutputPath <> None and validationInfo.TsOutputPath.Length > 0): processOption = ProcessOption.Process_copy else: processOption = ProcessOption.Process_input_timeseries # Remplace les valeurs nulles par une valeur de remplacement (interpolationlineaire) if (validationInfo.ReplaceValue <> None): replaceValueMethod = ReplaceValueMethod.With_constant replaceByValue = validationInfo.ReplaceValue replaceValue = None try: outputTimeSeries = ReplaceValuesTool( ts, replaceValueMethod, periodOption, replaceOption, processOption, startDate, endDate, replaceValue, replaceByValue, replaceByValueForExceededRate, rangeMax, rangeMin, rangeOption, maxRateOfChange, rateOfChangeUnit, rateOfChangeOption, maxGapUnit, maxGap) if (outputTimeSeries <> None and outputTimeSeries.Count > 0): ts = outputTimeSeries[0] except Exception, e: message = 'Execute Replace Value Tool: ' + e.ToString() WriteError(message) # Limit_Rate_Of_Change if (validationInfo.MaxRateOfChange <> None): replaceValueMethod = ReplaceValueMethod.Limit_rate_of_change maxRateOfChange = validationInfo.MaxRateOfChange rateOfChangeOption = RateOfChangeOption.With_constant rateOfChangeUnit = ReplaceTool_RateOfChangeUnit.Per_hour replaceByValue = validationInfo.ReplaceValue replaceValue = validationInfo.ReplaceValue replaceByValueForExceededRate = validationInfo.ReplaceValue try: outputTimeSeries = ReplaceValuesTool( ts, replaceValueMethod, periodOption, replaceOption, processOption, startDate, endDate, replaceValue, replaceByValue, replaceByValueForExceededRate, rangeMax, rangeMin, rangeOption, maxRateOfChange, rateOfChangeUnit, rateOfChangeOption, maxGapUnit, maxGap) if (outputTimeSeries <> None and outputTimeSeries.Count > 0): ts = outputTimeSeries[0] except Exception, e: message = 'Execute Replace Value Tool: ' + e.ToString() WriteError(message) # Replace_Range_With_Constant if (validationInfo.RangeMax <> None and validationInfo.RangeMin <> None): replaceValueMethod = ReplaceValueMethod.Replace_range_with_constant rangeOption = RangeOption.Replace_outside_range rangeMax = validationInfo.RangeMax rangeMin = validationInfo.RangeMin replaceByValue = validationInfo.ReplaceValue replaceValue = validationInfo.ReplaceValue try: outputTimeSeries = ReplaceValuesTool( ts, replaceValueMethod, periodOption, replaceOption, processOption, startDate, endDate, replaceValue, replaceByValue, replaceByValueForExceededRate, rangeMax, rangeMin, rangeOption, maxRateOfChange, rateOfChangeUnit, rateOfChangeOption, maxGapUnit, maxGap) if (outputTimeSeries <> None and outputTimeSeries.Count > 0): ts = outputTimeSeries[0] except Exception, e: message = 'Execute Replace Value Tool: ' + e.ToString() WriteError(message)
def ImportTS(spreadSheetPath, forecastTime, hindcastPeriod, forecastPeriod): """ <Script> <Author>VS</Author> <Description>Import time series to MC</Description> <Parameters> <Parameter name="spreadSheetPath" type="string">Path to the spreadsheet configuration.</Parameter> <Parameter name="forecastTime" type="string">Time of forecast (date and time when we will begin to import forecast data).</Parameter> <Parameter name="hindcastPeriod" type="int">Hindcast period in hour.</Parameter> <Parameter name="forecastPeriod" type="int">Forecast period in hour.</Parameter> </Parameters> </Script> """ # excel = None success = True # default = Excel.XlRangeValueDataType.xlRangeValueDefault logString = "Spreadsheet: {0}.".format(spreadSheetPath) #Convert dates from String format to DateTime format forecastTime = DateTime.ParseExact(forecastTime, 'MM/dd/yyyy HH:mm:ss', System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None) print "TOF" , forecastTime try: timeShift = 4 forecastTimeUtc = forecastTime.AddHours(timeShift) hindcastTime = forecastTime.AddHours(-hindcastPeriod) forecastEndTime = forecastTime.AddHours(forecastPeriod) print "TOF" , forecastTime print forecastEndTime print hindcastTime logString = logString + "\nTime of forecast: {0} UTC: {1}.".format(forecastTime,forecastTimeUtc) logString = logString + "\nFrom time: {0}. Hindcast period: {1} hours.".format(hindcastTime,hindcastPeriod) logString = logString + "\n To time: {0}. Forecast period: {1} hours.".format(forecastEndTime,forecastPeriod) # ts manager tsMgr = app.Modules.Get("Time series Manager") q = Query() q.Add(QueryElement('datetime', hindcastTime, QueryOperator.Gte)) q.Add(QueryElement('datetime', forecastEndTime, QueryOperator.Lte)) # spreadsheet sheetName = "Sheet1" sheetMgr = app.Modules.Get("Spreadsheet Manager") importSheetConfig = sheetMgr.OpenSpreadsheet(spreadSheetPath) i = 1 # by rows in spreadsheet while sheetMgr.GetCellValue(importSheetConfig, sheetName, i, 1): tsFullName = sheetMgr.GetCellValue(importSheetConfig, sheetName, i, 1) fileExtension = sheetMgr.GetCellValue(importSheetConfig, sheetName, i, 5) a = sheetMgr.GetCellValue(importSheetConfig, sheetName, i, 2) b = sheetMgr.GetCellValue(importSheetConfig, sheetName, i, 3) fileFullName = a + "\\" + b dateTimeSuffixFileFormat = sheetMgr.GetCellValue(importSheetConfig, sheetName, i, 4) if (dateTimeSuffixFileFormat != None): fileFullName = fileFullName + forecastTimeUtc.ToString(sheetMgr.GetCellValue(importSheetConfig, sheetName, i, 4)) fileFullName = fileFullName + fileExtension logString = logString + "\n\nFile: {0}\nTo TS: {1}.".format(fileFullName, tsFullName) if os.path.isfile(fileFullName): # get ts ts = tsMgr.TimeSeriesList.Fetch(tsFullName) ts.Query(q) #itemsQuery = ts.Fetch(q) numberOfHeaderLines = sheetMgr.GetCellValue(importSheetConfig, sheetName, i, 7) timeZone = sheetMgr.GetCellValue(importSheetConfig, sheetName, i, 10) curTimeShift = timeShift if (timeZone != None): if (timeZone.upper() == "GUADELOUPE"): curTimeShift = 0 else: logString = logString + "\n Unknown time zone: '{0}'. UTC is used.".format(timeZone) success = False if (fileExtension == ".csv") or (fileExtension == ".tsv"): with open(fileFullName, 'rb') as csvfile: delimit = sheetMgr.GetCellValue(importSheetConfig, sheetName, i, 6) if (delimit.upper() == 'TAB'): delimit = '\t' spamreader = csv.reader(csvfile, delimiter=delimit) r = 0 newItems = [] updateItems = [] totalUpdate = 0 for row in spamreader: r = r + 1 if (r <= numberOfHeaderLines) or (row.Count < 2): continue rowDate = DateTime.ParseExact(row[0], sheetMgr.GetCellValue(importSheetConfig, sheetName, i, 8), None).AddHours(-curTimeShift) if hindcastTime <= rowDate and rowDate <= forecastEndTime: rowValue = float(row[1].replace(sheetMgr.GetCellValue(importSheetConfig, sheetName, i, 9), '.')) # add/update steps in TS curStep = ts.CreateNew() curStep.XValue = rowDate curStep.YValue = rowValue if ts.Contains(rowDate): updateItems.append(curStep) else: newItems.append(curStep) ts.Query(Query()) ts.Add(newItems) ts.Update(updateItems) tsMgr.TimeSeriesList.Update(ts, True) if newItems.Count==0 and updateItems.Count==0: logString = logString + "\n!!! No Data." success = False else: logString = logString + "\n Inserted: {0}. Updated: {1}.".format(newItems.Count, updateItems.Count) logString = logString + "\n Last imported time step: {0}.".format(curStep.XValue) elif (fileExtension == ".xls"): xmlSheetName = sheetMgr.GetCellValue(importSheetConfig, sheetName, i, 11) dateCol = sheetMgr.GetCellValue(importSheetConfig, sheetName, i, 12) valCol = sheetMgr.GetCellValue(importSheetConfig, sheetName, i, 13) # Create a new empty workbook set. workbookSet = Factory.GetWorkbookSet(); # Open the saved workbook from memory. workbook = workbookSet.Workbooks.Open(fileFullName); # System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo("en-US") # workbook = excel.Workbooks.Open(fileFullName) ws = workbook.Worksheets[xmlSheetName] r = numberOfHeaderLines newItems = [] updateItems = [] totalUpdate = 0 while (True): r = r + 1 #ddd = ws.Cells(r, 2).Value[default] #vvv = ws.Cells(r, 3).Value2 # rowDate = ws.Cells[r, dateCol].Value[default] # rowDate = ws.Cells[r, dateCol].Value A = int(r - 1) B = int(dateCol - 1) print A, B rowDate = ws.Cells[A,B].Value if (rowDate == None): break rowDate = DateTime.FromOADate(rowDate) rowDate = rowDate.AddHours(-curTimeShift) C = int(valCol - 1) if hindcastTime <= rowDate and rowDate <= forecastEndTime: rowValue = ws.Cells[A, C].Value # add/update steps in TS curStep = ts.CreateNew() curStep.XValue = rowDate curStep.YValue = rowValue if ts.Contains(rowDate): updateItems.append(curStep) else: newItems.append(curStep) ts.Query(Query()) ts.Add(newItems) ts.Update(updateItems) tsMgr.TimeSeriesList.Update(ts, True) if newItems.Count==0 and updateItems.Count==0: logString = logString + "\n!!! No Data." success = False else: logString = logString + "\n Inserted: {0}. Updated: {1}.".format(newItems.Count, updateItems.Count) logString = logString + "\n Last imported time step: {0}.".format(curStep.XValue) else: logString = logString + "\n!!! Unknown file format!" success = False else: logString = logString + "\n!!! Cannot find file." success = False i += 1 except Exception as exc: logString = logString + "\n!!! Cannot import timeseries!\n!!! Error: {0}".format(exc) success = False # console.show(locals()) # if excel != None: # excel.Quit() # log print logString if success is False: raise NameError(logString) pass;
def __init__(self, dbAbonent, xmlAbonent, user): self.db = misbus.get_internal_remote(dbAbonent) self.user = self.db.execute_query( 'select id from _s_user where kod={0}'.format(user)).data[0][0] self.server = self.db.execute_query( 'select top 1 ID_Server1 from _a_Option ').data[0][0] remote = misbus.get_external_remote(xmlAbonent) operation = remote.get_operation("GetAllPartsData") #Формирование пакета Table = self.db.execute_query("select * from {0}".format( self.tableName)).data for row in Table: self.dbTable.append({ 'ID': row[0], 'ID1': row[1], 'ID_SERVER': row[2], 'ID_LOGIN': row[3], 'DATETIME_C': row[4], 'C1ID': row[5], 'IDNOMENCLATURE': row[6], 'RELEASEDATE': row[7], 'EXPIRATIONDATE': row[8], 'EXTERNALNAME': row[9], 'IDPROIZV': row[10], 'IDCOUNTRY': row[11] }) op_input = operation.build_input_envelope({'name': "GetAllPartsData"}) op_result = operation.execute_and_parse(op_input) #парсинг XML xmldata = op_result.select_all('//PartData') lowerDate = DateTime.ParseExact("01/01/1753", 'dd/mm/yyyy', None) highDate = DateTime.ParseExact("12/31/9999", 'mm/dd/yyyy', None) for answer in xmldata: dictionary = {} s = answer.select('*/ReleaseDate').text releaseDate = None if s != None: try: releaseDate = DateTime.Parse(s) except Exception: releaseDate = None if releaseDate != None: dictionary['RELEASEDATE'] = releaseDate expirationDate = None s = answer.select('*/ExpirationDate').text if s != None: try: expirationDate = DateTime.Parse(s) except Exception: expirationDate = None if expirationDate > lowerDate and expirationDate < highDate: dictionary['EXPIRATIONDATE'] = expirationDate nomenclature = answer.select('*/IDNomenclature').text if nomenclature != None: dictionary['IDNOMENCLATURE'] = nomenclature external = answer.select('*/ExternalName').text if external != None: dictionary['EXTERNALNAME'] = external proizv = answer.select('*/IDManufacturer').text if proizv != None: dictionary['IDPROIZV'] = proizv country = answer.select('*/IDCountry').text if country != None: dictionary['IDCOUNTRY'] = country C1ID = answer.select('*/ID').text if C1ID != None: dictionary['C1ID'] = C1ID self.xmlData.append(dictionary) '''
def GetDateTimeFromISO8601FormattedDate(isoFormattedDate): return DateTime.ParseExact( isoFormattedDate, ISO8601_FORMAT_LOCAL, CultureInfo.InvariantCulture )