def DisplayTemporal( self, locData, field, startData, stopData ): timeCap = float( self.m_SpinTime.GetValue() ) / 10.0 endData=stopData # divide time interval into even sections daySteps = self.m_StepsCtrl.GetValue() if self.sort: dayDelta = ( startData - stopData ) /daySteps else: dayDelta = ( stopData - startData ) / daySteps # IMPORTANT NOTE # ALL DATES WILL BE BINNED BY DAYS uniqueLoc = [] if self.m_CheckBin.IsChecked(): BinFloor = float( self.m_BinStartCtrl.GetValue() ) BinCeil = float( self.m_BinEndCtrl.GetValue() ) else: BinFloor,BinCeil = 0,0 # get cases from start date to current simulation date curData = startData # minData = str(curData.month) + '/' + str(curData.day) + '/' + str(curData.year) minData = startData lastData = minData for loc in GenGIS.layerTree.GetLocationLayers(): loc.GetController().SetActive(False) while self.SortedPass( curData, endData ): # GenGIS.viewport.Refresh() if self.m_CheckBin.IsChecked(): minData = curData for loc in uniqueLoc: loc.GetController().SetActive(False) startTime = time.time() # curDateStr = str(curData.month) + '/' + str(curData.day) + '/' + str(curData.year) numCases = {} lastReportedCase = {} uniqueLoc = [] if not self.sort: temCur = curData + timedelta(days=BinCeil) temMin = minData - timedelta(days=BinFloor) else: temCur = curData - timedelta(days=BinFloor) temMin = minData + timedelta(days=BinCeil) temCur = str(temCur.month) + '/' + str(temCur.day) + '/' + str(temCur.year) temMin = str(temMin.month) + '/' + str(temMin.day) + '/' + str(temMin.year) for key in self.locData.keys(): data = self.locData[key] if not self.sort: filteredData = dh.genericFilter(data, temCur, filterFunc.lessEqualDate) filteredData = dh.genericFilter(filteredData, temMin, filterFunc.greaterEqualDate) else: filteredData = dh.genericFilter(data, temCur, filterFunc.greaterEqualDate) filteredData = dh.genericFilter(filteredData, temMin, filterFunc.lessEqualDate) for fieldData in filteredData: loc = GenGIS.layerTree.GetLocationLayer(key) locDate = self.dateStrToDate(fieldData) id = loc.GetController().GetId() if id in numCases: numCases[id] = numCases[id] + 1 if lastReportedCase[id] < locDate: lastReportedCase[id] = locDate else: numCases[id] = 1 lastReportedCase[id] = locDate uniqueLoc.append(loc) # set visual properties of location sites for loc in uniqueLoc: if not self.StartingState[loc.GetName()]: continue id= loc.GetController().GetId() deltaDate = curData - lastReportedCase[id] if self.ColourIntensity: loc.GetController().SetColour(self.ColourSetter(deltaDate.days)) else: loc.GetController().SetColour(loc.GetController().GetColour()) loc.GetController().SetActive(True) if self.isSequence: loc.GetController().SetSize(self.SizeSetter(numCases[id])) self.ShowSequences(loc) # set date of label #self.label.SetText(str(curData.month) + "/" + str(curData.day) + "/" + str(curData.year)) # update grid and polygons GenGIS.layerTree.GetLocationSetLayer(0).UpdateGridAndPolygons() GenGIS.layerTree.UpdatePythonState() GenGIS.SafeYield() GenGIS.viewport.Refresh() # increment curData. Takes into account rounding errors when another loop needs to be run, # but is shy of the final date lastData = curData if self.sort: if curData - dayDelta < endData and curData != endData: curData = endData else: curData = curData - dayDelta else: if curData + dayDelta > endData and curData != endData: curData = endData else: curData = curData + dayDelta # Check if I should be printing if self.m_saveSpreadCheckBox.IsChecked(): self.PrintSpread() elapsedTime = time.time() - startTime if elapsedTime < timeCap: time.sleep(timeCap - elapsedTime)
def DisplayText( self, locData, startData, stopData ): # show spread of virus on a data basis timeCap = float( self.m_SpinTime.GetValue() ) / 10.0 # Need to add a fudge of -1 so that a Delta of 2 will include 0,1 then 2,3 etc Delta = math.ceil( self.m_StartChoice.GetCount() / float(self.m_StepsCtrl.GetValue()) ) # get cases from start date to current simulation date # curData = startData curIndex = self.m_StartChoice.FindString(startData) stopIndex = self.m_StartChoice.FindString(stopData) minDataStr = str(startData) uniqueLoc = [] if self.m_CheckBin.IsChecked(): BinFloor = float( self.m_BinStartCtrl.GetValue() ) BinCeil = float( self.m_BinEndCtrl.GetValue() ) else: BinFloor,BinCeil = 0,0 for loc in GenGIS.layerTree.GetLocationLayers(): loc.GetController().SetActive(False) curIndex = curIndex + Delta - 1 #needs a slight rounding adjustment as floats are ugly while curIndex <= stopIndex : #get current data curData = self.m_StartChoice.GetString(curIndex) # if curIndex + BinCeil <= stopIndex: # binCeilDataStr = self.m_StartChoice.GetString(curIndex + BinCeil) # else: binCeilDataStr = self.m_StartChoice.GetString(curIndex) curDataStr = str(curData) # check if binning is used. If it is, update the indexes if self.m_CheckBin.IsChecked(): if curIndex - BinFloor < 0: lastData = self.m_StartChoice.GetString(0) else: lastData = self.m_StartChoice.GetString(curIndex - BinFloor) minDataStr = str(lastData) for loc in uniqueLoc: loc.GetController().SetActive(False) startTime = time.time() numCases = {} lastReportedCase = {} uniqueLoc = [] for key in self.locData.keys(): data = self.locData[key] if not self.sort: filteredData = dh.genericFilter(data, binCeilDataStr , filterFunc.lessEqual) filteredData = dh.genericFilter(filteredData, minDataStr , filterFunc.greaterEqual) else: filteredData = dh.genericFilter(data, binCeilDataStr , filterFunc.greaterEqual) filteredData = dh.genericFilter(filteredData, minDataStr, filterFunc.lessEqual) #convert sequence to it's location if possible for fieldData in filteredData: # determine number of cases and last reported case for all locations loc = GenGIS.layerTree.GetLocationLayer(key) id = loc.GetController().GetId() if id in numCases: numCases[id] = numCases[id] + 1 if lastReportedCase[id] < fieldData: lastReportedCase[id] = curIndex else: numCases[id] = 1 lastReportedCase[id] = curIndex uniqueLoc.append(loc) # set visual properties of location sites for loc in uniqueLoc: if not self.StartingState[loc.GetName()]: continue id= loc.GetController().GetId() deltaDate = stopIndex - lastReportedCase[loc.GetController().GetId()] if self.ColourIntensity: loc.GetController().SetColour(self.ColourSetter(deltaDate)) else: loc.GetController().SetColour(loc.GetController().GetColour()) #Don't really know what this does, but it screws with how locations are drawn # loc.GetController().SetRenderingOrder(deltaDate) loc.GetController().SetActive(True) if self.isSequence: loc.GetController().SetSize(self.SizeSetter(numCases[id])) self.ShowSequences(loc) # set date of label #self.label.SetText(curData) # update grid and polygons GenGIS.layerTree.GetLocationSetLayer(0).UpdateGridAndPolygons() GenGIS.layerTree.UpdatePythonState() GenGIS.SafeYield() GenGIS.viewport.Refresh() curIndex = curIndex + Delta # Check if I should be printing if self.m_saveSpreadCheckBox.IsChecked(): self.PrintSpread() elapsedTime = time.time() - startTime if elapsedTime < timeCap: time.sleep(timeCap - elapsedTime)
def DisplayNumeric( self, locData, startData, stopData ): # show spread of virus on a data basis timeCap = float( self.m_SpinTime.GetValue() ) / 10.0 startData,stopData = float(startData),float(stopData) Delta = (stopData - startData) / float(self.m_StepsCtrl.GetValue()) curData = startData minData = startData lastData = startData uniqueLoc = [] if self.m_CheckBin.IsChecked(): BinFloor = float( self.m_BinStartCtrl.GetValue() ) BinCeil = float( self.m_BinEndCtrl.GetValue() ) else: BinFloor,BinCeil = 0,0 for loc in GenGIS.layerTree.GetLocationLayers(): loc.GetController().SetActive(False) while self.SortedPass( curData, stopData ): if self.m_CheckBin.IsChecked(): # minData = lastData minData = curData for loc in uniqueLoc: loc.GetController().SetActive(False) startTime = time.time() # determine number of cases and last reported case for all locations numCases = {} lastReportedCase = {} uniqueLoc = [] # print "Cur = ",curData," Ceil = ",curData + BinCeil, " Floor = ", minData - BinFloor for key in self.locData.keys(): data = self.locData[key] # ascending if not self.sort: filteredData = dh.genericFilter(data, curData + BinCeil, filterFunc.lessEqualFloat) filteredData = dh.genericFilter(filteredData, minData - BinFloor, filterFunc.greaterEqualFloat) #descending else: filteredData = dh.genericFilter(data, curData - BinFloor , filterFunc.greaterEqualFloat) filteredData = dh.genericFilter(filteredData, minData + BinCeil , filterFunc.lessEqualFloat) #convert sequence to it's location if possible for fieldData in filteredData: #need to get int value of location layer loc = GenGIS.layerTree.GetLocationLayer(key) id = loc.GetController().GetId() if id in numCases.keys(): numCases[id] = numCases[id] + 1 if lastReportedCase[id] < fieldData: lastReportedCase[id] = fieldData else: numCases[id] = 1 lastReportedCase[id] = fieldData uniqueLoc.append(loc) # set visual properties of location sites for loc in uniqueLoc: if not self.StartingState[loc.GetName()]: continue id = loc.GetController().GetId() if float(lastReportedCase[id] < 0 ): deltaDate = curData + float(lastReportedCase[id]) else: deltaDate = curData - float(lastReportedCase[id]) if self.ColourIntensity: loc.GetController().SetColour(self.ColourSetter(deltaDate)) else: loc.GetController().SetColour(loc.GetController().GetColour()) # loc.GetController().SetRenderingOrder(deltaDate) loc.GetController().SetActive(True) if self.isSequence: loc.GetController().SetSize(self.SizeSetter(numCases[id])) self.ShowSequences(loc) # set text of label #self.label.SetText("%.2f" %curData) # update grid and polygons GenGIS.layerTree.GetLocationSetLayer(0).UpdateGridAndPolygons() GenGIS.layerTree.UpdatePythonState() GenGIS.SafeYield() GenGIS.viewport.Refresh() #curData = float(curData) + Delta # if curData + Delta > float(stopData) and curData != float(stopData): # curData = float(stopData) # else: lastData = curData curData = float(curData) + Delta # Check if I should be printing if self.m_saveSpreadCheckBox.IsChecked(): self.PrintSpread() elapsedTime = time.time() - startTime if elapsedTime < timeCap: time.sleep(timeCap - elapsedTime)
def DisplayTemporal(self, locData, field, startData, stopData): timeCap = float(self.m_SpinTime.GetValue()) / 10.0 endData = stopData # divide time interval into even sections daySteps = self.m_StepsCtrl.GetValue() if self.sort: dayDelta = (startData - stopData) / daySteps else: dayDelta = (stopData - startData) / daySteps # IMPORTANT NOTE # ALL DATES WILL BE BINNED BY DAYS uniqueLoc = [] if self.m_CheckBin.IsChecked(): BinFloor = float(self.m_BinStartCtrl.GetValue()) BinCeil = float(self.m_BinEndCtrl.GetValue()) else: BinFloor, BinCeil = 0, 0 # get cases from start date to current simulation date curData = startData # minData = str(curData.month) + '/' + str(curData.day) + '/' + str(curData.year) minData = startData lastData = minData for loc in GenGIS.layerTree.GetLocationLayers(): loc.GetController().SetActive(False) while self.SortedPass(curData, endData): # GenGIS.viewport.Refresh() if self.m_CheckBin.IsChecked(): minData = curData for loc in uniqueLoc: loc.GetController().SetActive(False) startTime = time.time() # curDateStr = str(curData.month) + '/' + str(curData.day) + '/' + str(curData.year) numCases = {} lastReportedCase = {} uniqueLoc = [] if not self.sort: temCur = curData + timedelta(days=BinCeil) temMin = minData - timedelta(days=BinFloor) else: temCur = curData - timedelta(days=BinFloor) temMin = minData + timedelta(days=BinCeil) temCur = str(temCur.month) + "/" + str(temCur.day) + "/" + str(temCur.year) temMin = str(temMin.month) + "/" + str(temMin.day) + "/" + str(temMin.year) for key in self.locData.keys(): data = self.locData[key] if not self.sort: filteredData = dh.genericFilter(data, temCur, filterFunc.lessEqualDate) filteredData = dh.genericFilter(filteredData, temMin, filterFunc.greaterEqualDate) else: filteredData = dh.genericFilter(data, temCur, filterFunc.greaterEqualDate) filteredData = dh.genericFilter(filteredData, temMin, filterFunc.lessEqualDate) for fieldData in filteredData: loc = GenGIS.layerTree.GetLocationLayer(key) locDate = self.dateStrToDate(fieldData) id = loc.GetController().GetId() if id in numCases: numCases[id] = numCases[id] + 1 if lastReportedCase[id] < locDate: lastReportedCase[id] = locDate else: numCases[id] = 1 lastReportedCase[id] = locDate uniqueLoc.append(loc) # set visual properties of location sites for loc in uniqueLoc: if not self.StartingState[loc.GetName()]: continue id = loc.GetController().GetId() deltaDate = curData - lastReportedCase[id] if self.ColourIntensity: loc.GetController().SetColour(self.ColourSetter(deltaDate.days)) else: loc.GetController().SetColour(loc.GetController().GetColour()) loc.GetController().SetActive(True) if self.isSequence: loc.GetController().SetSize(self.SizeSetter(numCases[id])) self.ShowSequences(loc) # set date of label # self.label.SetText(str(curData.month) + "/" + str(curData.day) + "/" + str(curData.year)) # update grid and polygons GenGIS.layerTree.GetLocationSetLayer(0).UpdateGridAndPolygons() GenGIS.layerTree.UpdatePythonState() GenGIS.SafeYield() GenGIS.viewport.Refresh() # increment curData. Takes into account rounding errors when another loop needs to be run, # but is shy of the final date lastData = curData if self.sort: if curData - dayDelta < endData and curData != endData: curData = endData else: curData = curData - dayDelta else: if curData + dayDelta > endData and curData != endData: curData = endData else: curData = curData + dayDelta # Check if I should be printing if self.m_saveSpreadCheckBox.IsChecked(): self.PrintSpread() elapsedTime = time.time() - startTime if elapsedTime < timeCap: time.sleep(timeCap - elapsedTime)
def DisplayText(self, locData, startData, stopData): # show spread of virus on a data basis timeCap = float(self.m_SpinTime.GetValue()) / 10.0 # Need to add a fudge of -1 so that a Delta of 2 will include 0,1 then 2,3 etc Delta = math.ceil(self.m_StartChoice.GetCount() / float(self.m_StepsCtrl.GetValue())) # get cases from start date to current simulation date # curData = startData curIndex = self.m_StartChoice.FindString(startData) stopIndex = self.m_StartChoice.FindString(stopData) minDataStr = str(startData) uniqueLoc = [] if self.m_CheckBin.IsChecked(): BinFloor = float(self.m_BinStartCtrl.GetValue()) BinCeil = float(self.m_BinEndCtrl.GetValue()) else: BinFloor, BinCeil = 0, 0 for loc in GenGIS.layerTree.GetLocationLayers(): loc.GetController().SetActive(False) curIndex = curIndex + Delta - 1 # needs a slight rounding adjustment as floats are ugly while curIndex <= stopIndex: # get current data curData = self.m_StartChoice.GetString(curIndex) # if curIndex + BinCeil <= stopIndex: # binCeilDataStr = self.m_StartChoice.GetString(curIndex + BinCeil) # else: binCeilDataStr = self.m_StartChoice.GetString(curIndex) curDataStr = str(curData) # check if binning is used. If it is, update the indexes if self.m_CheckBin.IsChecked(): if curIndex - BinFloor < 0: lastData = self.m_StartChoice.GetString(0) else: lastData = self.m_StartChoice.GetString(curIndex - BinFloor) minDataStr = str(lastData) for loc in uniqueLoc: loc.GetController().SetActive(False) startTime = time.time() numCases = {} lastReportedCase = {} uniqueLoc = [] for key in self.locData.keys(): data = self.locData[key] if not self.sort: filteredData = dh.genericFilter(data, binCeilDataStr, filterFunc.lessEqual) filteredData = dh.genericFilter(filteredData, minDataStr, filterFunc.greaterEqual) else: filteredData = dh.genericFilter(data, binCeilDataStr, filterFunc.greaterEqual) filteredData = dh.genericFilter(filteredData, minDataStr, filterFunc.lessEqual) # convert sequence to it's location if possible for fieldData in filteredData: # determine number of cases and last reported case for all locations loc = GenGIS.layerTree.GetLocationLayer(key) id = loc.GetController().GetId() if id in numCases: numCases[id] = numCases[id] + 1 if lastReportedCase[id] < fieldData: lastReportedCase[id] = curIndex else: numCases[id] = 1 lastReportedCase[id] = curIndex uniqueLoc.append(loc) # set visual properties of location sites for loc in uniqueLoc: if not self.StartingState[loc.GetName()]: continue id = loc.GetController().GetId() deltaDate = stopIndex - lastReportedCase[loc.GetController().GetId()] if self.ColourIntensity: loc.GetController().SetColour(self.ColourSetter(deltaDate)) else: loc.GetController().SetColour(loc.GetController().GetColour()) # Don't really know what this does, but it screws with how locations are drawn # loc.GetController().SetRenderingOrder(deltaDate) loc.GetController().SetActive(True) if self.isSequence: loc.GetController().SetSize(self.SizeSetter(numCases[id])) self.ShowSequences(loc) # set date of label # self.label.SetText(curData) # update grid and polygons GenGIS.layerTree.GetLocationSetLayer(0).UpdateGridAndPolygons() GenGIS.layerTree.UpdatePythonState() GenGIS.SafeYield() GenGIS.viewport.Refresh() curIndex = curIndex + Delta # Check if I should be printing if self.m_saveSpreadCheckBox.IsChecked(): self.PrintSpread() elapsedTime = time.time() - startTime if elapsedTime < timeCap: time.sleep(timeCap - elapsedTime)
def DisplayNumeric(self, locData, startData, stopData): # show spread of virus on a data basis timeCap = float(self.m_SpinTime.GetValue()) / 10.0 startData, stopData = float(startData), float(stopData) Delta = (stopData - startData) / float(self.m_StepsCtrl.GetValue()) curData = startData minData = startData lastData = startData uniqueLoc = [] if self.m_CheckBin.IsChecked(): BinFloor = float(self.m_BinStartCtrl.GetValue()) BinCeil = float(self.m_BinEndCtrl.GetValue()) else: BinFloor, BinCeil = 0, 0 for loc in GenGIS.layerTree.GetLocationLayers(): loc.GetController().SetActive(False) while self.SortedPass(curData, stopData): if self.m_CheckBin.IsChecked(): # minData = lastData minData = curData for loc in uniqueLoc: loc.GetController().SetActive(False) startTime = time.time() # determine number of cases and last reported case for all locations numCases = {} lastReportedCase = {} uniqueLoc = [] # print "Cur = ",curData," Ceil = ",curData + BinCeil, " Floor = ", minData - BinFloor for key in self.locData.keys(): data = self.locData[key] # ascending if not self.sort: filteredData = dh.genericFilter(data, curData + BinCeil, filterFunc.lessEqualFloat) filteredData = dh.genericFilter(filteredData, minData - BinFloor, filterFunc.greaterEqualFloat) # descending else: filteredData = dh.genericFilter(data, curData - BinFloor, filterFunc.greaterEqualFloat) filteredData = dh.genericFilter(filteredData, minData + BinCeil, filterFunc.lessEqualFloat) # convert sequence to it's location if possible for fieldData in filteredData: # need to get int value of location layer loc = GenGIS.layerTree.GetLocationLayer(key) id = loc.GetController().GetId() if id in numCases.keys(): numCases[id] = numCases[id] + 1 if lastReportedCase[id] < fieldData: lastReportedCase[id] = fieldData else: numCases[id] = 1 lastReportedCase[id] = fieldData uniqueLoc.append(loc) # set visual properties of location sites for loc in uniqueLoc: if not self.StartingState[loc.GetName()]: continue id = loc.GetController().GetId() if float(lastReportedCase[id] < 0): deltaDate = curData + float(lastReportedCase[id]) else: deltaDate = curData - float(lastReportedCase[id]) if self.ColourIntensity: loc.GetController().SetColour(self.ColourSetter(deltaDate)) else: loc.GetController().SetColour(loc.GetController().GetColour()) # loc.GetController().SetRenderingOrder(deltaDate) loc.GetController().SetActive(True) if self.isSequence: loc.GetController().SetSize(self.SizeSetter(numCases[id])) self.ShowSequences(loc) # set text of label # self.label.SetText("%.2f" %curData) # update grid and polygons GenGIS.layerTree.GetLocationSetLayer(0).UpdateGridAndPolygons() GenGIS.layerTree.UpdatePythonState() GenGIS.SafeYield() GenGIS.viewport.Refresh() # curData = float(curData) + Delta # if curData + Delta > float(stopData) and curData != float(stopData): # curData = float(stopData) # else: lastData = curData curData = float(curData) + Delta # Check if I should be printing if self.m_saveSpreadCheckBox.IsChecked(): self.PrintSpread() elapsedTime = time.time() - startTime if elapsedTime < timeCap: time.sleep(timeCap - elapsedTime)