diff --git a/odmtools/controller/frmSeriesSelector.py b/odmtools/controller/frmSeriesSelector.py index c306e7d..f83b008 100755 --- a/odmtools/controller/frmSeriesSelector.py +++ b/odmtools/controller/frmSeriesSelector.py @@ -162,7 +162,7 @@ def OnTableRightDown(self, event): # build pop-up menu for right-click display self.selectedIndex = event.m_itemIndex #self.selectedID = self.tableSeries.getColumnText(event.m_itemIndex, 1) - self.selectedID = self.tblSeries.GetSelectedObject().id + self.selectedID = self.tblSeries.GetSelectedObject().resultID # print self.selectedID popup_edit_series = wx.NewId() @@ -374,7 +374,7 @@ def siteAndVariables(self): :return: """ - self.site_code = self.siteList[self.cbSites.Selection].VariableCode + self.site_code = self.siteList[self.cbSites.Selection].SamplingFeatureCode self.cbVariables.Clear() self.varList = self.series_service.get_variables_by_site_code(self.site_code) @@ -400,7 +400,7 @@ def siteOnly(self): self.cbSites.Enabled = True self.variable_code = None - self.site_code = self.siteList[self.cbSites.Selection].code + self.site_code = self.siteList[self.cbSites.Selection].SamplingFeatureCode self.setFilter(site_code=self.site_code) def variableOnly(self): @@ -460,17 +460,17 @@ def setFilter(self, site_code='', var_code='', advfilter=''): :return: """ if site_code and var_code: - self.siteFilter = TextSearch(self.tblSeries, columns=self.tblSeries.columns[3:4],text=site_code) - self.variableFilter = TextSearch(self.tblSeries, columns=self.tblSeries.columns[6:7],text=var_code) + self.siteFilter = TextSearch(self.tblSeries, columns=self.tblSeries.columns[0:10],text=site_code) + self.variableFilter = TextSearch(self.tblSeries, columns=self.tblSeries.columns[0:10],text=var_code) self.tblSeries.SetFilter(Chain(self.siteFilter, self.variableFilter)) elif site_code: - self.tblSeries.SetFilter(TextSearch(self.tblSeries, columns=self.tblSeries.columns[3:4], text=site_code)) + self.tblSeries.SetFilter(TextSearch(self.tblSeries, columns=self.tblSeries.columns[0:10], text=site_code)) elif var_code: - self.tblSeries.SetFilter(TextSearch(self.tblSeries, columns=self.tblSeries.columns[6:7], text=var_code)) + self.tblSeries.SetFilter(TextSearch(self.tblSeries, columns=self.tblSeries.columns[0:10], text=var_code)) elif advfilter: self.tblSeries.SetFilter(advfilter) else: - self.tblSeries.SetFilter(TextSearch(self.tblSeries, columns=self.tblSeries.columns[0:1])) + self.tblSeries.SetFilter(TextSearch(self.tblSeries, columns=self.tblSeries.columns[0:10])) self.tblSeries.RepopulateList() @@ -492,12 +492,12 @@ def onReadyToPlot(self, event): object = self.tblSeries.GetSelectedObject() if not self.tblSeries.IsChecked(object): - Publisher.sendMessage("removePlot", seriesID=object.id) + Publisher.sendMessage("removePlot", seriesID=object.ResultID) Publisher.sendMessage("updateCursor", deselectedObject=object) else: logger.debug("Obtained object, entering addplot") - self.pnlPlot.addPlot(self.memDB, object.id) + self.pnlPlot.addPlot(self.memDB, object.ResultID) Publisher.sendMessage("updateCursor", selectedObject=object) logger.debug("refreshing...") @@ -524,7 +524,7 @@ def getSelectedObject(self, event): ## update Cursor if self.parent.Parent.pnlPlot._seriesPlotInfo: - if self.parent.Parent.pnlPlot._seriesPlotInfo.isPlotted(editingObject.id): + if self.parent.Parent.pnlPlot._seriesPlotInfo.isPlotted(editingObject.ResultID): #print "Updating Cursor", editingObject.id Publisher.sendMessage("updateCursor", selectedObject=editingObject) @@ -563,7 +563,7 @@ def onReadyToEdit(self): ovl.RefreshObject(ovl.editingObject) - return True, object.id#, self.memDB + return True, object.ResultID#, self.memDB else: isSelected = False logger.debug("series was not checked") diff --git a/odmtools/controller/logicPlotOptions.py b/odmtools/controller/logicPlotOptions.py index cb521c7..dfa7d2c 100644 --- a/odmtools/controller/logicPlotOptions.py +++ b/odmtools/controller/logicPlotOptions.py @@ -54,7 +54,7 @@ def __init__(self, prnt): self.plotTitle = None self.numBins = 25 self.binWidth = 1.5 - self.boxWhiskerMethod = "Month" + self.boxWhiskerMethod = "month" self.yrange = 0 self.color = "" @@ -226,8 +226,10 @@ def getSelectedSeries(self, seriesID): return self.createSeriesInfo(seriesID, seriesInfo, series) def createSeriesInfo(self, seriesID, seriesInfo, series): - startDate = series.begin_date_time - endDate = series.end_date_time + + dates = self.memDB.series_service.get_result_dates(series.ResultID) + startDate = dates[1] + endDate = dates[0] if endDate > self.endDate: self.endDate = endDate @@ -237,14 +239,15 @@ def createSeriesInfo(self, seriesID, seriesInfo, series): if not self.isSubsetted: self.currentStart = self.startDate self.currentEnd = self.endDate - - variableName = series.variable_name - unitsName = series.variable_units_name - siteName = series.site_name - dataType = series.data_type - variable = self.memDB.series_service.get_variable_by_id(series.variable_id) - - noDataValue = variable.no_data_value +#TODO odm2 + + unitsName = series.UnitsObj.UnitsName + siteName = series.FeatureActionObj.SamplingFeatureObj.SamplingFeatureName + dataType = "datatype"#series.data_type + #variable = self.memDB.series_service.get_variable_by_id(series.variable_id) + variable =series.VariableObj + variableName = variable.VariableNameCV + noDataValue = variable.NoDataValue if self.editID == seriesID: #d= DataFrame(pandas.read_sql()) logger.debug("editing -- getting datavalues for graph") @@ -256,6 +259,7 @@ def createSeriesInfo(self, seriesID, seriesInfo, series): data = self.memDB.getDataValuesforGraph(seriesID, noDataValue, self.currentStart, self.currentEnd) logger.debug("Finished plotting -- getting datavalues for graph") + logger.debug("assigning variables...") seriesInfo.seriesID = seriesID seriesInfo.series = series @@ -266,13 +270,13 @@ def createSeriesInfo(self, seriesID, seriesInfo, series): seriesInfo.siteName = siteName seriesInfo.variableName = variableName seriesInfo.variableUnits = unitsName - seriesInfo.plotTitle = "Site: " + siteName + "\nVarName: " + variableName + "\nQCL: " + series.quality_control_level_code - seriesInfo.axisTitle = variableName + " (" + unitsName + ")" + seriesInfo.plotTitle = "Site: %s \nVarName: %s \nQCL: %s" %(siteName, variableName, series.ProcessingLevelID) + seriesInfo.axisTitle = "%s (%s)"%(variableName, unitsName) seriesInfo.noDataValue = noDataValue seriesInfo.dataTable = data if len(data) > 0: - seriesInfo.yrange = np.max(data['DataValue']) - np.min(data['DataValue']) + seriesInfo.yrange = np.max(data['datavalue']) - np.min(data['datavalue']) else: seriesInfo.yrange = 0 @@ -298,9 +302,9 @@ def getSeriesInfo(self, seriesID): def buildPlotInfo(self, seriesInfo): #remove all of the nodatavalues from the pandas table - filteredData = seriesInfo.dataTable[seriesInfo.dataTable["DataValue"] != seriesInfo.noDataValue] - val = filteredData["Month"].map(calcSeason) - filteredData["Season"] = val + filteredData = seriesInfo.dataTable[seriesInfo.dataTable["datavalue"] != seriesInfo.noDataValue] + val = filteredData["month"].map(calcSeason) + filteredData["season"] = val # construct tasks for the task server tasks = [("Probability", filteredData), @@ -353,12 +357,12 @@ class Statistics(object): def __init__(self, data): start_time = timeit.default_timer() - dvs = data["DataValue"] + dvs = data["datavalue"] count = len(dvs) if count > 0: time = timeit.default_timer() - self.NumberofCensoredObservations = len(data[data["CensorCode"] != "nc"]) + self.NumberofCensoredObservations = len(data[data["censorcodecv"] != "nc"]) elapsed = timeit.default_timer() - time logger.debug("censored observations using len: %s" % elapsed) @@ -396,13 +400,13 @@ def __init__(self, data, method): self.intervals = {} self.method = method - interval_types = ["Overall", "Year", "Month", "Season"] - intervals = ["Overall", "Year", "Month", "Season"] + interval_types = ["overall", "year", "month", "season"] + intervals = ["overall", "year", "month", "season"] interval_options = zip(interval_types, intervals) for interval_type, interval in interval_options: start_time = timeit.default_timer() - if interval_type == "Overall": + if interval_type == "overall": interval = data else: interval = data.groupby(interval_type) @@ -421,18 +425,18 @@ def calculateBoxWhiskerData(self, interval, interval_type): results = self.calculateIntervalsOnGroups(interval) - if interval_type == "Season" or interval_type == "Month": + if interval_type == "season" or interval_type == "month": func = None - if interval_type == "Season": + if interval_type == "season": func = numToSeason - elif interval_type == "Month": + elif interval_type == "month": func = numToMonth self.intervals[interval_type] = BoxWhiskerPlotInfo( interval_type, interval_type, [func(x) for x in results["names"]], [results["median"], results["conflimit"], results["mean"], results["confint"]]) - elif interval_type == "Overall": + elif interval_type == "overall": self.intervals[interval_type] = BoxWhiskerPlotInfo( interval_type, None, [], [results["median"], results["conflimit"], results["mean"], results["confint"]]) @@ -452,7 +456,7 @@ def calculateIntervalsOnGroups(self, interval): if isinstance(interval, pd.core.groupby.DataFrameGroupBy): for name, group in interval: - datavalue = group['DataValue'] + datavalue = group['datavalue'] group_mean = np.mean(datavalue) group_median = np.median(datavalue) group_std = math.sqrt(np.var(datavalue)) @@ -467,8 +471,8 @@ def calculateIntervalsOnGroups(self, interval): median.append(group_median) mean.append(group_mean) else: - name = "Overall" - datavalue = interval['DataValue'] + name = "overall" + datavalue = interval['datavalue'] data_mean = np.mean(datavalue) data_median = np.median(datavalue) data_std = math.sqrt(np.var(datavalue)) @@ -539,7 +543,7 @@ def __init__(self, data): :param data: :return: """ - self.yAxis = data['DataValue'] + self.yAxis = data['datavalue'] # Determine rank, sorting values doesn't change outcome while using pandas. ranks = self.yAxis.rank() PrbExc = ranks / (len(ranks) + 1) * 100 diff --git a/odmtools/gui/mnuRibbon.py b/odmtools/gui/mnuRibbon.py index 360f6cc..389c1ce 100755 --- a/odmtools/gui/mnuRibbon.py +++ b/odmtools/gui/mnuRibbon.py @@ -658,7 +658,7 @@ def enableButtons(self, plot, isActive): self.spnBins.Enabled = False self.enableDateSelection(True) - ##HIstogram + ##Histogram elif plot == 2: self.PlotsOptions_bar.EnableButton(wxID_RIBBONPLOTTSTYPE, False) self.PlotsOptions_bar.EnableButton(wxID_RIBBONPLOTTSLEGEND, False) diff --git a/odmtools/gui/plotBoxWhisker.py b/odmtools/gui/plotBoxWhisker.py index ea6ef84..3058d7d 100644 --- a/odmtools/gui/plotBoxWhisker.py +++ b/odmtools/gui/plotBoxWhisker.py @@ -116,17 +116,17 @@ def _createPlot(self, oneSeries, rows, cols, index): ax.scatter([range(1, len(med) + 1)], med, marker='s', c="k", s=10) # bp = onSeries.dataTable.boxplot( - bp = oneSeries.dataTable[oneSeries.dataTable["DataValue"]<>oneSeries.noDataValue].boxplot(column="DataValue", ax=ax, by=oneSeries.BoxWhisker.currinterval.groupby, + bp = oneSeries.dataTable[oneSeries.dataTable["datavalue"]<>oneSeries.noDataValue].boxplot(column="datavalue", ax=ax, by=oneSeries.BoxWhisker.currinterval.groupby, rot=35, notch=True, sym="-s", conf_intervals=ci, return_type='dict', grid=False) # Set Colors of the Box Whisker plot try: - plt.setp(bp['DataValue']['whiskers'], color='k', linestyle='-') - plt.setp(bp['DataValue']['medians'], color='k', linestyle='-') - plt.setp(bp['DataValue']['boxes'], color='GREY', linestyle='-') - plt.setp(bp['DataValue']['caps'], color='k') - plt.setp(bp['DataValue']['fliers'], markersize=3.5, color=oneSeries.color) + plt.setp(bp['datavalue']['whiskers'], color='k', linestyle='-') + plt.setp(bp['datavalue']['medians'], color='k', linestyle='-') + plt.setp(bp['datavalue']['boxes'], color='GREY', linestyle='-') + plt.setp(bp['datavalue']['caps'], color='k') + plt.setp(bp['datavalue']['fliers'], markersize=3.5, color=oneSeries.color) except: plt.setp(bp['whiskers'], color='k', linestyle='-') plt.setp(bp['medians'], color='k', linestyle='-') @@ -169,22 +169,22 @@ def setColor(self, color): def monthly(self, str): # print "monthly" - self.seriesPlotInfo.setBoxInterval("Month") + self.seriesPlotInfo.setBoxInterval("month") self.updatePlot() def seasonaly(self, str): # print"seasonal" - self.seriesPlotInfo.setBoxInterval("Season") + self.seriesPlotInfo.setBoxInterval("season") self.updatePlot() def yearly(self, str): # print "yearly" - self.seriesPlotInfo.setBoxInterval("Year") + self.seriesPlotInfo.setBoxInterval("year") self.updatePlot() def overall(self, str): # print "overall" - self.seriesPlotInfo.setBoxInterval("Overall") + self.seriesPlotInfo.setBoxInterval("overall") self.updatePlot() diff --git a/odmtools/gui/plotTimeSeries.py b/odmtools/gui/plotTimeSeries.py index d5026b1..2fbfd20 100755 --- a/odmtools/gui/plotTimeSeries.py +++ b/odmtools/gui/plotTimeSeries.py @@ -412,7 +412,7 @@ def updatePlot(self): data = oneSeries.dataTable dates = data.index.astype(datetime.datetime) #data.plot(ax=curraxis) - curraxis.plot_date(dates, data['DataValue'], + curraxis.plot_date(dates, data['datavalue'], color=oneSeries.color, fmt=self.format, xdate=True, tz=None, antialiased=True, label=oneSeries.plotTitle, alpha=self.alpha, picker=5.0, pickradius=5.0, markersize=4) @@ -484,7 +484,7 @@ def updateCursor(self, selectedObject=None, deselectedObject=None): Activate Cursor. Happens when a plot is selected """ if self.seriesPlotInfo: - seriesInfo = self.seriesPlotInfo.getSeries(selectedObject.id) + seriesInfo = self.seriesPlotInfo.getSeries(selectedObject.ResultID) if seriesInfo: currentAxis = None diff --git a/odmtools/odmservices/series_service.py b/odmtools/odmservices/series_service.py index 34b3e17..a91dec1 100644 --- a/odmtools/odmservices/series_service.py +++ b/odmtools/odmservices/series_service.py @@ -43,6 +43,10 @@ def reset_session(self): def get_used_sites(self): + """ + Return a list of all sites that are being referenced in the Series Catalog Table + :return: List[Sites] + """ try: fas=[x[0] for x in self._session.query(distinct(Results.FeatureActionID)).all()] except: @@ -54,6 +58,10 @@ def get_used_sites(self): return sites def get_used_variables(self): + """ + #get list of used variable ids + :return: List[Variables] + """ try: ids= [x[0] for x in self._session.query(distinct(Results.VariableID)).all()] except: @@ -63,9 +71,36 @@ def get_used_variables(self): return vars + + # Query DetailedResultInfo/series object is for Display purposes + def get_all_series(self): + """ + Returns all series as a modelObject + :return: List[Series] + """ return self.read.getDetailedResultInfo('Time Series Coverage') + def get_series_by_id(self, series_id): + """ + + :param series_id: int + :return: Series + """ + # try: + # return self.read.getDetailedResultInfo('Time Series Coverage', resultID = series_id)[0] + # except Exception as e: + # print e + # return None + return self.read.getResults(ids=[series_id])[0] + + # Query result objects for data purposes + def get_result_dates(self, result_id): + q = self.read._session.query( + func.max(TimeSeriesResultValues.ValueDateTime), func.min(TimeSeriesResultValues.ValueDateTime) + ).filter(TimeSeriesResultValues.ResultID == result_id) + return q.all()[0] + def get_variables_by_site_code(self, site_code): """ Finds all of variables at a site @@ -74,44 +109,21 @@ def get_variables_by_site_code(self, site_code): """ try: var_ids = [x[0] for x in - self._session.query(distinct(Results.VariableID)) \ - .filter(Results.FeatureActionID == FeatureActions.FeatureActionID) \ - .filter(FeatureActions.SamplingFeatureID == SamplingFeatures.SamplingFeatureID) \ - .filter(SamplingFeatures.SamplingFeatureCode == site_code) + self._session.query(distinct(Results.VariableID)) + .filter(Results.FeatureActionID == FeatureActions.FeatureActionID) + .filter(FeatureActions.SamplingFeatureID == SamplingFeatures.SamplingFeatureID) + .filter(SamplingFeatures.SamplingFeatureCode == site_code).all() ] except: var_ids = None + q = self._session.query(Variables).filter(Variables.VariableID.in_(var_ids)) + return q.all() -# def get_variables_by_site_code(self, site_code): # covers NoDV, VarUnits, TimeUnits -# """ -# Finds all of variables at a site -# :param site_code: str -# :return: List[Variables] -# """ -# try: -# var_ids = [x[0] for x in self._edit_session.query(distinct(Series.variable_id)).filter_by( -# site_code=site_code).all()] -# except: -# var_ids = None -# -# variables = [] -# for var_id in var_ids: -# variables.append(self._edit_session.query(Variable).filter_by(id=var_id).first()) -# -# return variables - # Series Catalog methods -# def get_all_series(self): -# """ -# Returns all series as a modelObject -# :return: List[Series] -# """ -# -# #logger.debug("%s" % self._edit_session.query(Series).order_by(Series.id).all()) -# return self._edit_session.query(Series).order_by(Series.id).all() + # # def get_series_by_site(self , site_id): # """ @@ -124,18 +136,7 @@ def get_variables_by_site_code(self, site_code): # return selectedSeries # except: # return None -# -# def get_series_by_id(self, series_id): -# """ -# -# :param series_id: int -# :return: Series -# """ -# try: -# return self._edit_session.query(Series).filter_by(id=series_id).first() -# except Exception as e: -# print e -# return None + # @@ -148,60 +149,22 @@ def get_variables_by_site_code(self, site_code): # return self._edit_session.query(Site).order_by(Site.code).all() # # -# def get_used_sites(self): -# """ -# Return a list of all sites that are being referenced in the Series Catalog Table -# :return: List[Sites] -# """ -# try: -# site_ids = [x[0] for x in self._edit_session.query(distinct(Series.site_id)).all()] -# except: -# site_ids = None # -# if not site_ids: -# return None -# -# Sites = [] -# for site_id in site_ids: -# Sites.append(self._edit_session.query(Site).filter_by(id=site_id).first()) -# -# return Sites - -# -# -# def get_site_by_id(self, site_id): -# """ -# return a Site object that has an id=site_id -# :param site_id: integer- the identification number of the site -# :return: Sites -# """ + def get_site_by_id(self, site_id): + """ + return a Site object that has an id=site_id + :param site_id: integer- the identification number of the site + :return: Sites + """ # try: # return self._edit_session.query(Site).filter_by(id=site_id).first() # except: # return None + + return self.read.getSampling(ids = [site_id])[0] + # -# # Variables methods -# def get_used_variables(self): -# """ -# #get list of used variable ids -# :return: List[Variables] -# """ -# -# try: -# var_ids = [x[0] for x in self._edit_session.query(distinct(Series.variable_id)).all()] -# except: -# var_ids = None -# -# if not var_ids: -# return None -# -# Variables = [] -# -# #create list of variables from the list of ids -# for var_id in var_ids: -# Variables.append(self._edit_session.query(Variable).filter_by(id=var_id).first()) -# -# return Variables + # # def get_all_variables(self): # """ @@ -210,16 +173,17 @@ def get_variables_by_site_code(self, site_code): # """ # return self._edit_session.query(Variable).all() # -# def get_variable_by_id(self, variable_id): -# """ -# -# :param variable_id: int -# :return: Variables -# """ + def get_variable_by_id(self, variable_id): + """ + + :param variable_id: int + :return: Variables + """ # try: # return self._edit_session.query(Variable).filter_by(id=variable_id).first() # except: # return None + return self.read.getVariables(ids = [variable_id])[0] # # def get_variable_by_code(self, variable_code): # """ @@ -402,30 +366,38 @@ def get_variables_by_site_code(self, site_code): # pass # # -# #Data Value Methods -# def get_values_by_series(self, series_id): -# ''' -# -# :param series_id: Series id -# :return: pandas dataframe -# ''' -# series= self.get_series_by_id(series_id) -# if series: -# q = self._edit_session.query(DataValue).filter_by( -# site_id=series.site_id, -# variable_id=series.variable_id, -# method_id=series.method_id, -# source_id=series.source_id, -# quality_control_level_id=series.quality_control_level_id) -# -# query=q.statement.compile(dialect=self._session_factory.engine.dialect) -# data= pd.read_sql_query(sql= query, -# con = self._session_factory.engine, -# params = query.params ) -# #return data.set_index(data['LocalDateTime']) -# return data -# else: -# return None + #Data Value Methods + def get_values_by_series(self, series_id): + ''' + + :param series_id: Series id + :return: pandas dataframe + ''' + #series= self.get_series_by_id(series_id) + # if series: + # q = self._edit_session.query(DataValue).filter_by( + # site_id=series.site_id, + # variable_id=series.variable_id, + # method_id=series.method_id, + # source_id=series.source_id, + # quality_control_level_id=series.quality_control_level_id) + # + # query=q.statement.compile(dialect=self._session_factory.engine.dialect) + # data= pd.read_sql_query(sql= query, + # con = self._session_factory.engine, + # params = query.params ) + # #return data.set_index(data['LocalDateTime']) + # return data + # else: + # return None + + q = self.read._session.query(TimeSeriesResultValues).filter_by(ResultID=series_id).order_by(TimeSeriesResultValues.ValueDateTime) + query = q.statement.compile(dialect=self._session_factory.engine.dialect) + data = pd.read_sql_query(sql=query, + con=self._session_factory.engine, + params=query.params) + data.set_index(data['valuedatetime'], inplace=True) + return data # # def get_all_values_df(self): # """ @@ -456,19 +428,20 @@ def get_variables_by_site_code(self, site_code): # def get_all_values(self): # return self._edit_session.query(DataValue).order_by(DataValue.local_date_time).all() # -# @staticmethod -# def calcSeason(row): -# -# month = int(row["Month"]) -# -# if month in [1, 2, 3]: -# return 1 -# elif month in[4, 5, 6]: -# return 2 -# elif month in [7, 8, 9]: -# return 3 -# elif month in [10, 11, 12]: -# return 4 + @staticmethod + def calcSeason(row): + + month = int(row["month"]) + + if month in [1, 2, 3]: + return 1 + elif month in[4, 5, 6]: + return 2 + elif month in [7, 8, 9]: + return 3 + elif month in [10, 11, 12]: + return 4 + # # def get_all_plot_values(self): # """ @@ -490,30 +463,45 @@ def get_variables_by_site_code(self, site_code): # data["Season"] = data.apply(self.calcSeason, axis=1) # return data.set_index(data['LocalDateTime']) # -# def get_plot_values(self, seriesID, noDataValue, startDate = None, endDate = None ): -# """ -# -# :param seriesID: -# :param noDataValue: -# :param startDate: -# :param endDate: -# :return: -# """ -# series = self.get_series_by_id(seriesID) -# -# DataValues = [ -# (dv.data_value, dv.local_date_time, dv.censor_code, dv.local_date_time.strftime('%m'), -# dv.local_date_time.strftime('%Y')) -# for dv in series.data_values -# if dv.data_value != noDataValue if dv.local_date_time >= startDate if dv.local_date_time <= endDate -# ] -# data = pd.DataFrame(DataValues, columns=["DataValue", "LocalDateTime", "CensorCode", "Month", "Year"]) -# data.set_index(data['LocalDateTime'], inplace=True) -# data["Season"] = data.apply(self.calcSeason, axis=1) -# return data -# -# -# + def get_plot_values(self, seriesID, noDataValue, startDate = None, endDate = None ): + """ + + :param seriesID: + :param noDataValue: + :param startDate: + :param endDate: + :return: + """ + + #series = self.get_series_by_id(seriesID) + # + # DataValues = [ + # (dv.data_value, dv.local_date_time, dv.censor_code, dv.local_date_time.strftime('%m'), + # dv.local_date_time.strftime('%Y')) + # for dv in series.data_values + # if dv.data_value != noDataValue if dv.local_date_time >= startDate if dv.local_date_time <= endDate + # ] + # data = pd.DataFrame(DataValues, columns=["DataValue", "LocalDateTime", "CensorCode", "Month", "Year"]) + # data.set_index(data['LocalDateTime'], inplace=True) + # data["Season"] = data.apply(self.calcSeason, axis=1) + # return data + + + Values = self.get_values_by_series(seriesID) + data = Values[['datavalue', 'censorcodecv', 'valuedatetime']] + + + #data.set_index(data['LocalDateTime'], inplace=True) + data["month"] = data['valuedatetime'].apply(lambda x: x.month) + data["year"] = data['valuedatetime'].apply(lambda x: x.year) + data["season"] = data.apply(self.calcSeason, axis=1) + return data + + + + + + # def get_data_value_by_id(self, id): # """ #