///// <summary> ///// Print DataTable composed of tablename,datetime,value[,flag] ///// with columns for each tablename ///// </summary> ///// <param name="list"></param> ///// <param name="table"></param> //private static void PrintDataTable(SeriesList list, DataTable table, // Formatter fmt, TimeInterval interval) //{ // var t0 = ""; // if (table.Rows.Count > 0) // t0 = fmt.FormatDate(table.Rows[0][1]); // var vals = new string[list.Count]; // var flags = new string[list.Count]; // var dict = new Dictionary<string, int>(); // for (int i = 0; i < list.Count; i++) // { // dict.Add(list[i].Table.TableName, i); // } // string t = ""; // bool printThisRow = false; // for (int i = 0; i < table.Rows.Count; i++) // { // var row = table.Rows[i]; // t = fmt.FormatDate(row[1]); // if (t != t0) // { // if (printThisRow) // fmt.PrintRow(t0, vals, flags); // vals = new string[list.Count]; // flags = new string[list.Count]; // t0 = t; // } // vals[dict[row[0].ToString()]] = fmt.FormatNumber(row[2]); // flags[dict[row[0].ToString()]] = fmt.FormatFlag(row[3]); // DateTime date = Convert.ToDateTime(row[1]); // bool topOfHour = date.Minute == 0; // printThisRow = fmt.HourlyOnly == false || (fmt.HourlyOnly && topOfHour); // } // if (printThisRow) // fmt.PrintRow(t, vals, flags); //} private static TimeSeriesName[] GetTimeSeriesName(NameValueCollection query, TimeInterval interval) { List <TimeSeriesName> rval = new List <TimeSeriesName>(); //add support for the auto generated parameter list //if the sites list is just the site return a list of all parameters in the table var sites = HydrometWebUtility.GetParameter(query, "list"); Logger.WriteLine("GetTimeSeriesName()"); Logger.WriteLine(query.ToString()); var siteCodePairs = sites.Split(','); foreach (var item in siteCodePairs) { var tokens = item.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (tokens.Length == 2) { TimeSeriesName tn = new TimeSeriesName(tokens[0] + "_" + tokens[1], interval); rval.Add(tn); } } return(rval.ToArray()); }
public override void WriteSeriesHeader(SeriesList list) { WriteLine(HydrometWebUtility.HydrometHeader()); WriteLine("BEGIN DATA"); string headLine = "DATE "; if (m_interval == TimeInterval.Irregular || m_interval == TimeInterval.Hourly) { headLine = "DATE TIME "; } foreach (var item in list) { TimeSeriesName tn = new TimeSeriesName(item.Table.TableName); if (m_interval == TimeInterval.Daily) { //fprintf(stdout,", %4.8s %-4.8s",params[i].station,params[i].pcode); headLine += delim + " " + tn.siteid.PadRight(4) + " " + tn.pcode.PadRight(4); } else { headLine += delim + " " + tn.siteid.PadRight(8) + "" + tn.pcode.PadRight(8); } } headLine = headLine.ToUpper(); WriteLine(headLine); }
internal void Run() { if (query == "") { query = HydrometWebUtility.GetQuery(); } query = System.Uri.UnescapeDataString(query); var collection = HttpUtility.ParseQueryString(query); TimeRange r = GetDateRange(collection); var siteID = ""; if (collection.AllKeys.Contains("site")) { siteID = collection["site"]; } var parameter = ""; if (collection.AllKeys.Contains("parameter")) { parameter = collection["parameter"]; } Validation(siteID, parameter); if (collection.AllKeys.Contains("format")) { format = collection["format"]; } if (Array.IndexOf(supportedFormats, format) < 0) { StopWithError("Error: invalid format " + format); } if (format == "usgs-html") { PrintHtmlReport(r, siteID, parameter); } if (format == "csv-analysis") { PrintAnalysis(r, siteID, parameter); } }
internal string Run() { if (query == "") { query = HydrometWebUtility.GetQuery(); } if (query == "") { StopWithError("invalid query"); } query = System.Uri.UnescapeDataString(query); Logger.WriteLine("query='" + query + "'"); var collection = HttpUtility.ParseQueryString(query); var siteID = ""; if (collection.AllKeys.Contains("site")) { siteID = collection["site"].ToLower(); } if (siteID == "" || Regex.IsMatch(siteID, "[^a-zA-Z0-9_=]")) { StopWithError("invalid query"); } bool ui = LookupUI(collection); var interval = GetInterval(collection); string format = LookupFormat(collection); if (format == "html") { PrintHtmlInventory(siteID, interval, ui); } else if (format == "csv") { PrintCsvInve } return(m_sb.ToString()); }
/// <summary> /// convert queries such as: list=boii ob, bigi gh /// into an array of time series names. /// /// </summary> /// <param name="query"></param> /// <param name="interval"></param> /// <param name="db"></param> /// <returns></returns> private static TimeSeriesName[] GetTimeSeriesName(NameValueCollection query, TimeInterval interval, TimeSeriesDatabase db) { var custom_list = HydrometWebUtility.GetParameter(query, "custom_list"); if (custom_list == "idwr" && interval == TimeInterval.Irregular) { return(IdwrCustom.GetIDWRInstantList(db.Server).ToArray()); } else if (custom_list.ToLower().IndexOf("wd") == 0 && interval == TimeInterval.Daily) { return(IdwrCustom.GetIDWRDailyList(db.Server, custom_list).ToArray()); } List <TimeSeriesName> rval = new List <TimeSeriesName>(); var listParameter = HydrometWebUtility.GetParameter(query, "list"); Logger.WriteLine("GetTimeSeriesName()"); Logger.WriteLine(query.ToString()); var siteCodePairs = listParameter.ToLower().Split(','); foreach (var item in siteCodePairs) { var tokens = item.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (tokens.Length == 2) { TimeSeriesName tn = new TimeSeriesName(tokens[0] + "_" + tokens[1], interval); rval.Add(tn); } else if (tokens.Length == 1) {//just the site return a list of all parameters var parms = db.GetParameters(tokens[0].Trim(), interval, false); for (int i = 0; i < parms.Length; i++) { TimeSeriesName tn = new TimeSeriesName(tokens[0] + "_" + parms[i], interval); rval.Add(tn); } } } return(rval.ToArray()); }
internal void Run() { Console.Write("Content-type: text/html\n\n"); if (query == "") { query = HydrometWebUtility.GetQuery(); } var collection = HttpUtility.ParseQueryString(query); TimeRange r = GetDateRange(collection); var siteID = ""; if (collection.AllKeys.Contains("site")) { siteID = collection["site"]; } var parameter = ""; if (collection.AllKeys.Contains("parameter")) { parameter = collection["parameter"]; } var s = new HydrometDailySeries(siteID, parameter); var startYear = r.StartDate.Year; var endYear = r.EndDate.Year; DateTime t1 = r.StartDate; for (int i = startYear; i < endYear; i++) { s.Read(t1, t1.AddMonths(12)); DataTable wyTable = Usgs.WaterYearTable(s); var header = GetHeader(i + 1, siteID, parameter); var html = DataTableOutput.ToHTML(wyTable, true, "", header); Console.WriteLine(html); t1 = t1.AddMonths(12); } }
private void StopWithError(string msg) { PrintContentType(); Console.WriteLine(msg); Logger.WriteLine(msg); HydrometWebUtility.PrintHydrometTrailer(msg); if (m_interval == TimeInterval.Irregular) { Help.PrintInstant(); } if (m_interval == TimeInterval.Daily) { Help.PrintDaily(); } if (m_interval == TimeInterval.Monthly) { Help.PrintMonthly(); } throw new Exception(msg); }
public override void WriteSeriesHeader(SeriesList list) { if (m_printDescriptions) { HydrometWebUtility.PrintDisclamerLink(); WriteLine("<h3><h3>" + m_title + "</h3></h3>"); // LRS FB = Clear Lake Dam, CA - Reservoir Elevation - Feet // LRS FB2 = Clear Lake Dam, CA - Forebay Elevation below fish screens - Feet foreach (var s in list) { Logger.WriteLine(s.Name + " count = " + s.Count); var str = s.SiteID + " " + s.Parameter + " = " + s.SiteDescription() + " " + s.SeriesDescription() + "<br/>"; WriteLine(str); } } WriteLine("<table border=1>"); if (m_printHeader) { WriteLine("<tr>"); WriteLine("<th>DateTime</th>"); for (int i = 0; i < list.Count; i++) { TimeSeriesName tn = new TimeSeriesName(list[i].Table.TableName); WriteLine("<th>" + tn.siteid + "_" + tn.pcode + "</th>"); if (PrintFlags) { WriteLine("<th>flag</th>"); } } WriteLine("</tr>"); } }
internal void Run() { Console.Write("Content-type: text/html\n\n"); if (query == "") { query = HydrometWebUtility.GetQuery(); } if (query == "") { StopWithError("invalid query"); } query = System.Uri.UnescapeDataString(query); Logger.WriteLine("query='" + query + "'"); var collection = HttpUtility.ParseQueryString(query); var siteID = ""; if (collection.AllKeys.Contains("site")) { siteID = collection["site"].ToLower(); } if (siteID == "" || Regex.IsMatch(siteID, "[^a-zA-Z0-9_=]")) { StopWithError("invalid query"); } TimeInterval interval; bool ui = LookupUI(collection); SetInterval(collection, out interval); PrintInventory(siteID, interval, ui); }
private void InitFormatter(TimeInterval interval) { if (m_query == "") { m_query = HydrometWebUtility.GetQuery(); } Logger.WriteLine("Raw query: = '" + m_query + "'"); if (m_query == "") { StopWithError("Error: Invalid query"); } m_query = LegacyTranslation(m_query, interval); if (!ValidQuery(m_query)) { StopWithError("Error: Invalid query"); } m_collection = HttpUtility.ParseQueryString(m_query); if (!HydrometWebUtility.GetDateRange(m_collection, interval, out start, out end)) { StopWithError("Error: Invalid dates"); } string format = "2"; if (m_collection.AllKeys.Contains("format")) { format = m_collection["format"]; } // because of history daily defaults flags= false; // no flags (the old daily database did not have flags ) bool m_printFlags = interval == TimeInterval.Hourly || interval == TimeInterval.Irregular; if (m_collection.AllKeys.Contains("flags")) { m_printFlags = m_collection["flags"] == "true"; } bool printHeader = true; if (m_collection.AllKeys.Contains("header")) { printHeader = m_collection["header"] == "true"; } if (Array.IndexOf(supportedFormats, format) < 0) { StopWithError("Error: invalid format " + format); } if (format == "csv") { m_formatter = new CsvFormatter(interval, m_printFlags); } else if (format == "zrxp") { m_formatter = new WiskiFormatter(interval); } else if (format == "2") { m_formatter = new LegacyCsvFormatter(interval, m_printFlags); } else if (format == "1") { m_formatter = new LegacyCsvFormatter(interval, m_printFlags, "\t"); } else if (format == "html") { m_formatter = new HtmlFormatter(interval, m_printFlags, printHeader); } else { m_formatter = new LegacyCsvFormatter(interval, m_printFlags); } if (m_collection.AllKeys.Contains("print_hourly")) { m_formatter.HourlyOnly = m_collection["print_hourly"] == "true"; } }
private void StopWithError(string msg) { Logger.WriteLine(msg); HydrometWebUtility.PrintHydrometTrailer(msg); throw new Exception(msg); }
private static string LegacyStationQuery(string query, TimeInterval interval) { string rval = ""; var c = HttpUtility.ParseQueryString(query); var pcodes = c["pcode"].Split(','); var cbtt = c["station"]; var back = ""; var start = ""; var end = ""; var keys = c.AllKeys; if (keys.Contains("back")) { back = c["back"]; DateTime t1, t2; HydrometWebUtility.GetDateRange(c, interval, out t1, out t2); start = t1.ToString("yyyy-M-d"); end = t2.ToString("yyyy-M-d"); } else if (keys.Contains("year") && keys.Contains("month") && keys.Contains("day")) { var years = c["year"].Split(','); var months = c["month"].Split(','); var days = c["day"].Split(','); start = years[0] + "-" + months[0] + "-" + days[0]; end = years[1] + "-" + months[1] + "-" + days[1]; } rval = "list="; //rval = rval.Replace("station=" + cbtt + "", "list="); for (int i = 0; i < pcodes.Length; i++) { var pc = pcodes[i]; rval += cbtt + " " + pc; if (i != pcodes.Length - 1) { rval += ","; } } if (back == "") { rval += "&start=" + start + "&end=" + end; } if (c.AllKeys.Contains("print_hourly")) { rval += "&print_hourly=true"; } if (back != "") { rval += "&back=" + back; } if (c.AllKeys.Contains("format")) { rval += "&format=" + c["format"]; } if (c.AllKeys.Contains("header")) { rval += "&header=" + c["header"]; } if (c.AllKeys.Contains("flags")) { rval += "&flags=" + c["flags"]; } return(rval.ToLower()); }
public override void WriteSeriesTrailer() { HydrometWebUtility.PrintHydrometTrailer(); }
private void ParseQueryOptions(TimeInterval interval) { if (m_query == "") { m_query = HydrometWebUtility.GetQuery(); } m_query = System.Uri.UnescapeDataString(m_query); Logger.WriteLine("Raw query: = '" + m_query + "'"); if (m_query == "") { StopWithError("Error: Invalid query"); } m_query = LegacyTranslation(m_query, interval); if (!ValidQuery(m_query)) { StopWithError("Error: Invalid query"); } m_collection = HttpUtility.ParseQueryString(m_query); if (!HydrometWebUtility.GetDateRange(m_collection, interval, out start, out end)) { StopWithError("Error: Invalid dates"); } if (m_collection.AllKeys.Contains("format")) { format = m_collection["format"].Trim().ToLower(); } if (m_collection.AllKeys.Contains("title")) { title = m_collection["title"]; } // because of history daily defaults flags= false; // no flags (the old daily database did not have flags ) m_printFlags = interval == TimeInterval.Hourly || interval == TimeInterval.Irregular; if (interval == TimeInterval.Monthly) { m_printFlags = true; // historical default for monthly is flags } if (m_collection.AllKeys.Contains("flags")) { m_printFlags = m_collection["flags"] == "true"; } if (m_collection.AllKeys.Contains("header")) { printHeader = m_collection["header"] == "true"; } if (Array.IndexOf(supportedFormats, format) < 0) { StopWithError("Error: invalid format " + format); } }
public override void WriteSeriesTrailer() { WriteLine("END DATA"); HydrometWebUtility.PrintHydrometTrailer(); }