public static ChannelSearchResult FindByNameAndVariable(string name, Variable v) { ChannelSearchResult result; //TODO: try to use delegates in future version to eliminate duplicate code ChannelList channels = ChannelManager.GetListByStationNameAndVariable(name, v.Id); if (channels != null) { result = new ChannelSearchResult(channels); return result; } MessageWriter writer = new MessageWriter(); writer.VariableName = v.Name; StationList stations = StationManager.GetListByName(name); if (stations != null) { result = new ChannelSearchResult(stations); writer.StationName = stations[0].Name; result.ErrorMessage = writer.WriteErrorMessage(MessageType.NoStationVariable); return result; } result = new ChannelSearchResult(); result.ErrorMessage = writer.WriteErrorMessage(MessageType.NoStation); return result; }
public static ChannelSearchResult FindByStationIdAndVariable(int stId, Variable v) { ChannelSearchResult result; bool foundChannel = false; //bool foundStation = false; ChannelList channels = ChannelManager.GetListByStationAndVariable(stId, v.Id); if (channels.Count > 0) { result = new ChannelSearchResult(channels); foundChannel = true; return result; } //if the requested variable is daily precipitation - try to find //hourly precipitation instead if (foundChannel == false && v.VarEnum == VariableEnum.Precip) { //"1" means "hourly precipitation" channels = ChannelManager.GetListByStationAndVariable(stId, 1); if (channels.Count > 0) { foundChannel = true; foreach (Channel ch in channels) { ch.Variable = VariableManager.GetItemByEnum(VariableEnum.Precip); } result = new ChannelSearchResult(channels); return result; } } //channel not found --> search if a a station exists MessageWriter writer = new MessageWriter(); writer.VariableName = v.Name; Station station = StationManager.GetItemById(stId, false); if (station != null) { result = new ChannelSearchResult(); result.Stations.Add(station); writer.StationName = station.Name; result.ErrorMessage = writer.WriteErrorMessage(MessageType.NoStationVariable); return result; } result = new ChannelSearchResult(); result.ErrorMessage = writer.WriteErrorMessage(MessageType.NoStation); return result; }
/// <summary> /// Generates a new 'chart' image to be written to http output stream. /// Also saves the newly generated image to file on disk. /// </summary> /// <param name="ImagePath">Http request path of the chart image</param> public Bitmap GenerateImage(string ImagePath) { Bitmap bmp; ChartEngine ChartGen = new ChartEngine(); Width = 600; Height = 275; ShowText = true; QueryStringValidator QVal = new QueryStringValidator(ImagePath); QVal.Validate(); //the language and culture is also set in the validator if (QVal.IsValid) { // get query string parameters string lang = QVal.Culture; int StId = QVal.StationId; Variable curVar = QVal.Variable; DateTime startTime = QVal.StartDate; DateTime endTime = QVal.EndDate; // TODO: for longer intervals change curVar to [precip_day] // search for the channel corresponding to station/variable combination ChannelSearchResult found = ChannelSearchEngine.FindByStationIdAndVariable( StId, curVar); if (!found.HasMatchingStations) //no matching station { return ChartGen.CreateErrorChart(found.ErrorMessage); } if (found.HasMatchingChannels) //correct results found { Channel ch = found.Channels[0]; ITimeSeries ts; TimeInterval interval = new TimeInterval(startTime, endTime); MessageWriter writer = new MessageWriter(ch.Station.Name, ch.Variable.Name); // for precipitation, if it's hourly and a longer period, // always select daily precipitation to display a readable graph // otherwise, hourly precipitation will be displayed. int maxHourPrecipPeriod = 10; VariableEnum var = ch.Variable.VarEnum; if (var == VariableEnum.PrecipHour && interval.Length.TotalDays > maxHourPrecipPeriod) { var = VariableEnum.Precip; } //here we retrieve the time series ts = TimeSeriesManager.GetTimeSeries(ch, interval); if (ts.Count == 0) //this also means 'no data for time series' { bmp = ChartGen.CreateErrorChart (writer.WriteErrorMessage(MessageType.NoDataForPeriod)); } bmp = ChartGen.CreateChart(ch, ts); } else { // incorrect input - create a 'chart' with an error message bmp = ChartGen.CreateErrorChart(found.ErrorMessage); } } else { // incorrect input - create a 'chart' with an error message bmp = ChartGen.CreateErrorChart(QVal.ErrorMessage); } return bmp; }