static void Main(string[] args) { DTW ucrDtw; Query query; DTWResult result; int dimensions = Int16.Parse(args[2]); int queryStretchLength = Int16.Parse(args[3]); float warpingWindow = (float)Double.Parse(args[4]); ucrDtw = new DTW(dimensions, warpingWindow); query = ucrDtw.Query(); using (TextReader reader = new StreamReader(args[0])) { string line; while ((line = reader.ReadLine()) != null) { string[] strs = line.Split(' '); double[] a = new double[strs.Length]; for (int itt = 0; itt < strs.Length; itt++) { if (String.IsNullOrEmpty(strs[itt])) { continue; } a[itt] = double.Parse(strs[itt]); } ucrDtw.addDataItem(dimensions, a); } } List <double[]> source = new List <double[]>(); List <double[]> stretched; using (TextReader reader = new StreamReader(args[1])) { string line; while ((line = reader.ReadLine()) != null) { if (String.IsNullOrEmpty(line)) { continue; } string[] strs = line.Split(' '); double[] a = new double[dimensions]; for (int itt = 0; itt < strs.Length; itt++) { if (String.IsNullOrEmpty(strs[itt])) { continue; } a[itt] = double.Parse(strs[itt]); } source.Add(a); } } stretched = Utilities.stretchData(source, dimensions, queryStretchLength); //writeCsvFile("source.csv", source, dimensions); //writeCsvFile("stretched.csv", stretched, dimensions); foreach (double[] row in stretched) { query.addQueryItem(row); } result = ucrDtw.warp(query); Console.WriteLine("Distance: " + result.Distance); Console.WriteLine("Location: " + result.Location); }
static void Main() { var server = new WebSocketServer("ws://127.0.0.1:8181"); server.Start(socket => { socket.OnOpen = () => Console.WriteLine("Open!"); socket.OnClose = () => Console.WriteLine("Close!"); socket.OnMessage = message => { JObject j = JObject.Parse(message); int k = j.GetValue("k").ToObject <int>(); JArray searchseries = (JArray)j["searchseries"]; int dimensions = searchseries[0].ToObject <double[]>().Length; var sw = Stopwatch.StartNew(); DTW ucrDtw = new DTW(dimensions, k); foreach (JArray datapoint in searchseries) { ucrDtw.addDataItem(datapoint.ToObject <double[]>()); } JArray snippets = (JArray)j["querysnippets"]; DTWResult localresults; JArray matches = new JArray(); JArray distances = new JArray(); JArray queryids = new JArray(); int quid = 0; foreach (JArray snippet in snippets) { Query query = ucrDtw.Query(); foreach (JArray datapoint in snippet) { query.addQueryItem(datapoint.ToObject <double[]>()); } localresults = ucrDtw.warp(query); matches.Add(localresults.Locations); distances.Add(localresults.Distances); foreach (int thatloc in localresults.Locations) { queryids.Add(quid); } Console.WriteLine("Query " + quid + " finished."); quid = quid + 1; } sw.Stop(); JObject response = new JObject(); response.Add("querytime", Math.Round(sw.Elapsed.TotalMilliseconds) / 1000.0); response.Add("matchlocations", matches); response.Add("queryids", queryids); response.Add("distances", distances); socket.Send(response.ToString()); }; }); Console.WriteLine("Waiting for requests..."); var name = Console.ReadLine(); }