Beispiel #1
0
        public static void CompareLinuxToVMSCGI(string payload,TimeInterval interval= TimeInterval.Irregular)
        {
            //Program.Main(new string[] { "--cgi=instant", "--payload=?"+payload });

            TimeSeriesDatabase db = TimeSeriesDatabase.InitDatabase(new Arguments(new string[]{}));
            WebTimeSeriesWriter c = new WebTimeSeriesWriter(db,interval,payload);
            var fn = FileUtility.GetTempFileName(".txt");
            Console.WriteLine("linux temp file:"+fn);
            c.Run(fn);

            TextFile tf = new TextFile(fn);
            tf.DeleteLines(0, 1);

            var fnhyd0 = FileUtility.GetTempFileName(".txt");
            Console.WriteLine("vms temp file:" + fnhyd0);
            string url = "https://www.usbr.gov/pn-bin/webarccsv.pl?";

            if( interval == TimeInterval.Irregular || interval == TimeInterval.Hourly)
                url = "https://www.usbr.gov/pn-bin/webdaycsv.pl?";
            Web.GetFile(url + payload, fnhyd0);

              var tf2 = new TextFile(fnhyd0);

              if (!CompareHydrometData(tf, tf2))
              {
              // do detailed comparision.
              var diff = TextFile.Compare(tf, tf2);

              if (diff.Length > 0)
              {
                  for (int i = 0; i < tf.Length; i++)
                  {
                      Console.WriteLine(tf[i]);
                  }
              }
              Assert.IsTrue(diff.Length == 0);
              }
        }
Beispiel #2
0
        private static bool CompareHydrometData(TextFile a, TextFile b)
        {
            int idx1 = a.IndexOf("BEGIN DATA");
            a.DeleteLines(0,idx1);
            int idx2 = a.IndexOf("END DATA");
            a.DeleteLines(idx2, a.Length - 1);

            idx1 = b.IndexOf("BEGIN DATA");
            b.DeleteLines(0, idx1);
            idx2 = b.IndexOf("END DATA");
            b.DeleteLines(idx2, b.Length - 1);

            if (a.Length != b.Length)
                return false;

            for (int i = 0; i < a.Length; i++)
            {
                var x = a[i].Split(',');
                var y = b[i].Split(',');

                if (x.Length != y.Length)
                    return false;

                for (int j = 0; j < x.Length; j++)
                {
                    if (i == 0) // cbtt parameter
                    {// allow different spacing
                        // 'jck fb'   or 'jck     fb'
                        RegexOptions options = RegexOptions.None;
                        Regex regex = new Regex("[ ]{2,}", options);

                        x[j] = regex.Replace(x[j], " ");
                        y[j] = regex.Replace(y[j], " ");
                    }
                    if (x[j].Trim() != y[j].Trim())
                            return false;
                }
            }

            return true;
        }
Beispiel #3
0
        /// <summary>
        /// Compares data in two usgs rdb files, ignoring comments at the beginning
        /// </summary>
        /// <param name="tf1"></param>
        /// <param name="tf2"></param>
        /// <returns>true if there are differences in the data</returns>
        public static bool Diff(TextFile tf1, TextFile tf2)
        {
            var diff = System.Math.Abs(tf1.Length - tf2.Length);
            if ( diff > 5)
            {
                Logger.WriteLine("difference in length of files: " + diff);
                return true; //different number of lines in file
            }

            var idx1 = tf1.IndexOfRegex(@"^INDEP\s*SHIFT\s*DEP\s*STOR");
            var idx2 = tf2.IndexOfRegex(@"^INDEP\s*SHIFT\s*DEP\s*STOR");

            tf1.DeleteLines(0, idx1);
            tf2.DeleteLines(0, idx2);

            return TextFile.Compare(tf1, tf2).Length != 0;
        }