/// <summary> /// Convert all values in series to new unit /// </summary> /// <param name="originalSeries">Original series</param> /// <param name="newUnit">New unit</param> /// <returns>New series with converted values.</returns> public static Series ConvertSeries(Series originalSeries, Unit newUnit) { var conversionFunc = GetConversionFunc(originalSeries.Variable.VariableUnit, newUnit); var series = new Series(originalSeries, false) { Variable = (Variable)originalSeries.Variable.Clone() }; series.Variable.VariableUnit = newUnit; foreach (var dataValue in originalSeries.DataValueList) { var value = conversionFunc(dataValue.Value); series.AddDataValue(dataValue.LocalDateTime, value, dataValue.UTCOffset, dataValue.Qualifier); } return(series); }
/// <summary> /// This function gets the time series (date - value) /// </summary> private Series getSeriesFromTable(PolygonData polygon) { DataTable averageTable = getAverageTable(polygon); Series series = new Series(); series.Site = getSitesParameters(polygon); var site = polygon.sites.Find(f => f.variableName == VariableList.SelectedValue.ToString()); series.Variable = getVariablesParameters(site.variableID); series.CreationDateTime = DateTime.Now; series.LastCheckedDateTime = DateTime.Now; series.UpdateDateTime = DateTime.Now; foreach (DataRow row in averageTable.Rows) { series.AddDataValue((DateTime)row["LocalDateTime"], (Double)row["AVG(DataValues.DataValue)"]); } return(series); }
/// <summary> /// Defines the actions that occur every time an event is recognized /// </summary> /// <param name="anEvent">the event that was triggered</param> public void OnEvent(IEvent anEvent) { if (anEvent.Type == EventType.DataChanged) { //get the current time TimeStamp ts = (TimeStamp)anEvent.SimulationTime; // get the simulation start time if (getStartTime) { _start = ts.ModifiedJulianDay; } getStartTime = false; //get values ScalarSet vals = new ScalarSet(); Link link = new Link(); string linkID = null; foreach (string key in this._links.Keys) { link = (Link)_links[key]; //make sure it gets values from the link that sent the event if (link.TargetComponent == this && link.SourceComponent.ModelID == anEvent.Sender.ModelID) { //define theme string themeDescription = link.SourceElementSet.Description; string themeName = link.SourceElementSet.ID; Theme theme = new Theme(themeName, themeDescription); //save dt info for the timestep if (!_timestep.ContainsKey(themeName)) { _timestep.Add(themeName, new List <DateTime>()); } if (_timestep[themeName].Count < 2) { _timestep[themeName].Add(CalendarConverter.ModifiedJulian2Gregorian(ts.ModifiedJulianDay)); } //get link values vals = (ScalarSet)anEvent.Sender.GetValues(ts, key); //save link theme if (!themes.ContainsKey(link.ID)) { themes.Add(link.ID, theme); } //save link id linkID = link.SourceElementSet.ID; break; } } //if values are found, then store them if (vals.data.Length > 0) { int j = 0; try { while (j <= serieses.Count - 1) { //for(int k=0;k<= vals.data.Length-1;k++) //{ //checks to see if the value should be ignored. This is defined in omi. if (vals.data[j] != _ignore) { //get the site name string id = link.SourceElementSet.GetElementID(j); if (id == "") { id = link.SourceElementSet.ID + j.ToString(); } string sql = "SELECT s.SiteName " + "FROM Sites s " + "INNER JOIN DataSeries ds ON s.SiteID = ds.SiteID " + "WHERE ds.SeriesID= '" + id + "' "; //"ORDER BY dv.DataValue ASC"; DbOperations _db = new DbOperations(conn, DatabaseTypes.SQLite); System.Data.DataTable tbl = _db.LoadTable("values", sql); //string siteName = linkID + j.ToString(); string siteName = null; if (tbl.Rows.Count > 0) { siteName = tbl.Rows[0].ItemArray[0].ToString(); } else { siteName = (link.SourceElementSet.ID + "_" + link.SourceComponent.ModelID + "_loc" + j.ToString()).Replace(' ', '_'); } //check to see if series exists if (serieses.ContainsKey(siteName)) { //-- get the series Series series = serieses[siteName]; //-- store the associated theme if (!series.ThemeList.Contains(themes[link.ID])) { series.ThemeList.Add(themes[link.ID]); } //-- save data values series.AddDataValue(CalendarConverter.ModifiedJulian2Gregorian(ts.ModifiedJulianDay), vals.data[j]); } } //} j++; } } catch (IndexOutOfRangeException) { } } } }