<s> """<STR_LIT>""" <EOL> import datetime , time <EOL> class FCTimeSeries : <EOL> def __init__ ( self , temporalDomain , averageData ) : <EOL> self . temporalDomain = temporalDomain <EOL> self . averageData = averageData <EOL> self . combinedData = [ ] <EOL> self . initTimeSeriesData ( ) <EOL> self . combinedDataMiliSec = [ ] <EOL> self . plots = None <EOL> def timeSeriesDateToMilisecond ( self ) : <EOL> if self . temporalDomain . hourCellMode : <EOL> dt = datetime . timedelta ( hours = - <NUM_LIT:7> ) <EOL> else : <EOL> dt = datetime . timedelta ( hours = <NUM_LIT:1> ) <EOL> self . combinedDataMiliSec = self . combinedData <EOL> for point in self . combinedDataMiliSec : <EOL> shiftedTime = point [ <NUM_LIT:0> ] + dt <EOL> point [ <NUM_LIT:0> ] = time . mktime ( shiftedTime . timetuple ( ) ) * <NUM_LIT:1000> <EOL> return self . combinedDataMiliSec <EOL> def isLeapYear ( self , year ) : <EOL> return year > <NUM_LIT> and ( <NUM_LIT:0> == year % <NUM_LIT> or ( <NUM_LIT:0> == year % <NUM_LIT:4> and not <NUM_LIT:0> == year % <NUM_LIT:100> ) ) <EOL> def getNumericMonthDay ( self , yearNum , dayNum ) : <EOL> daysInFeb = <NUM_LIT> if self . isLeapYear ( yearNum ) else <NUM_LIT> <EOL> if dayNum <= <NUM_LIT> : <EOL> return [ <NUM_LIT:1> , dayNum ] <EOL> elif dayNum <= ( <NUM_LIT> + daysInFeb ) : <EOL> return [ <NUM_LIT:2> , dayNum - <NUM_LIT> ] <EOL> elif dayNum <= ( <NUM_LIT:2> * <NUM_LIT> + daysInFeb ) : <EOL> return [ <NUM_LIT:3> , dayNum - ( <NUM_LIT> + daysInFeb ) ] <EOL> elif dayNum <= ( <NUM_LIT:2> * <NUM_LIT> + <NUM_LIT:30> + daysInFeb ) : <EOL> return [ <NUM_LIT:4> , dayNum - ( <NUM_LIT:2> * <NUM_LIT> + daysInFeb ) ] <EOL> elif dayNum <= ( <NUM_LIT:3> * <NUM_LIT> + <NUM_LIT:30> + daysInFeb ) : <EOL> return [ <NUM_LIT:5> , dayNum - ( <NUM_LIT:2> * <NUM_LIT> + <NUM_LIT:30> + daysInFeb ) ] <EOL> elif dayNum <= ( <NUM_LIT:3> * <NUM_LIT> + <NUM_LIT:2> * <NUM_LIT:30> + daysInFeb ) : <EOL> return [ <NUM_LIT:6> , dayNum - ( <NUM_LIT:3> * <NUM_LIT> + <NUM_LIT:30> + daysInFeb ) ] <EOL> elif dayNum <= ( <NUM_LIT:4> * <NUM_LIT> + <NUM_LIT:2> * <NUM_LIT:30> + daysInFeb ) : <EOL> return [ <NUM_LIT:7> , dayNum - ( <NUM_LIT:3> * <NUM_LIT> + <NUM_LIT:2> * <NUM_LIT:30> + daysInFeb ) ] <EOL> elif dayNum <= ( <NUM_LIT:5> * <NUM_LIT> + <NUM_LIT:2> * <NUM_LIT:30> + daysInFeb ) : <EOL> return [ <NUM_LIT:8> , dayNum - ( <NUM_LIT:4> * <NUM_LIT> + <NUM_LIT:2> * <NUM_LIT:30> + daysInFeb ) ] <EOL> elif dayNum <= ( <NUM_LIT:5> * <NUM_LIT> + <NUM_LIT:3> * <NUM_LIT:30> + daysInFeb ) : <EOL> return [ <NUM_LIT:9> , dayNum - ( <NUM_LIT:5> * <NUM_LIT> + <NUM_LIT:2> * <NUM_LIT:30> + daysInFeb ) ] <EOL> elif dayNum <= ( <NUM_LIT:6> * <NUM_LIT> + <NUM_LIT:3> * <NUM_LIT:30> + daysInFeb ) : <EOL> return [ <NUM_LIT:10> , dayNum - ( <NUM_LIT:5> * <NUM_LIT> + <NUM_LIT:3> * <NUM_LIT:30> + daysInFeb ) ] <EOL> elif dayNum <= ( <NUM_LIT:6> * <NUM_LIT> + <NUM_LIT:4> * <NUM_LIT:30> + daysInFeb ) : <EOL> return [ <NUM_LIT:11> , dayNum - ( <NUM_LIT:6> * <NUM_LIT> + <NUM_LIT:3> * <NUM_LIT:30> + daysInFeb ) ] <EOL> elif dayNum <= ( <NUM_LIT:7> * <NUM_LIT> + <NUM_LIT:4> * <NUM_LIT:30> + daysInFeb ) : <EOL> return [ <NUM_LIT:12> , dayNum - ( <NUM_LIT:6> * <NUM_LIT> + <NUM_LIT:4> * <NUM_LIT:30> + daysInFeb ) ] <EOL> def timeSeriesDataSize ( self ) : <EOL> lenHours = len ( self . temporalDomain . hours ) if not self . temporalDomain . hourCellMode else <NUM_LIT:1> <EOL> lenDays = len ( self . temporalDomain . days ) if not self . temporalDomain . dayCellMode else <NUM_LIT:1> <EOL> lenYears = len ( self . temporalDomain . years ) if not self . temporalDomain . yearCellMode else <NUM_LIT:1> <EOL> return lenHours * lenDays * lenYears <EOL> def initTimeSeriesData ( self ) : <EOL> self . combinedData = [ ] <EOL> hours = [ <NUM_LIT:0> ] <EOL> if not self . temporalDomain . hourCellMode : <EOL> hours = self . temporalDomain . hours <EOL> days = [ <NUM_LIT:1> ] <EOL> if not self . temporalDomain . dayCellMode : <EOL> days = self . temporalDomain . days <EOL> if not self . temporalDomain . yearCellMode : <EOL> years = self . temporalDomain . years <EOL> tmpData = self . averageData if self . averageData else [ <NUM_LIT:0> for i in range ( len ( years ) * len ( days ) * len ( hours ) ) ] <EOL> else : <EOL> years = [ self . temporalDomain . years [ <NUM_LIT:0> ] , self . temporalDomain . years [ len ( self . temporalDomain . years ) - <NUM_LIT:1> ] ] <EOL> if isinstance ( self . averageData , list ) : <EOL> dataValue = self . averageData [ <NUM_LIT:0> ] if self . averageData else <NUM_LIT:0> <EOL> else : <EOL> dataValue = self . averageData if self . averageData else <NUM_LIT:0> <EOL> tmpData = [ dataValue for i in range ( len ( years ) * len ( days ) * len ( hours ) ) ] <EOL> dayLen = len ( days ) <EOL> hourLen = len ( hours ) <EOL> for i in range ( len ( years ) ) : <EOL> for j in range ( dayLen ) : <EOL> for k in range ( hourLen ) : <EOL> monthDay = self . getNumericMonthDay ( years [ i ] , days [ j ] ) <EOL> self . combinedData . append ( [ datetime . datetime ( years [ i ] , monthDay [ <NUM_LIT:0> ] , monthDay [ <NUM_LIT:1> ] , hours [ k ] ) , tmpData [ i * dayLen + j * hourLen + k ] ] ) <EOL> def getTimeSeriesPlot ( self , variableName , gridName , variableDescription , response = None , hashString = None ) : <EOL> timeseries_plot_object = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:x>' <EOL> } , <EOL> '<STR_LIT:title>' : { <EOL> '<STR_LIT:text>' : gridName <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : <NUM_LIT> * <NUM_LIT> , <EOL> '<STR_LIT:type>' : '<STR_LIT>' <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:title>' : { <EOL> '<STR_LIT:text>' : variableDescription <EOL> } , <EOL> '<STR_LIT>' : <NUM_LIT:0> <EOL> } , <EOL> '<STR_LIT>' : [ { <EOL> '<STR_LIT:name>' : variableDescription , <EOL> '<STR_LIT:data>' : self . combinedData <EOL> } ] , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : gridName , <EOL> '<STR_LIT>' : variableName , <EOL> '<STR_LIT>' : hashString , <EOL> '<STR_LIT>' : response . uri if response else None <EOL> } <EOL> } <EOL> return { '<STR_LIT>' : timeseries_plot_object , '<STR_LIT:width>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } </s>
