public static GDate ForGlobalhash(DateTime date) { // W30 adjustments var dowJonesDate = date.AddDays(-1); GDate inst = new GDate(date, dowJonesDate); return(inst); }
public static double[] CalculateFractions(string djia, GDate gdate) { string hashstring = gdate.ToString() + "-" + djia; // In the hash string we always use actual date string hash = GetMd5Hash(hashstring); var fraction1 = HexFraction(hash.Substring(0, 16)); var fraction2 = HexFraction(hash.Substring(16, 16)); double[] result = new double[] { fraction1, fraction2 }; return(result); }
public static GDate ForLongitude(DateTime date, int longitude) { var dowJonesDate = date; // W30 adjustments if (date >= w30breakdate && longitude > -30) { dowJonesDate = date.AddDays(-1); } GDate inst = new GDate(date, dowJonesDate); return(inst); }
public static string[] GetGlobalHash(DateTime date) { var gdate = GDate.ForGlobalhash(date); var djia = GetDowJonesAsync(gdate).ConfigureAwait(false).GetAwaiter().GetResult(); var fractions = CalculateFractions(djia, gdate); fractions[0] = fractions[0] * 180.0 - 90.0; fractions[1] = fractions[1] * 360.0 - 180.0; var result = (from f in fractions select f.ToString("F5")).ToArray(); return(result); }
public static string[] GetGeoHash(DateTime date, int latitude, int longitude) { var gdate = GDate.ForLongitude(date, longitude); var djia = GetDowJonesAsync(gdate).ConfigureAwait(false).GetAwaiter().GetResult(); var fractions = CalculateFractions(djia, gdate); fractions[0] = (fractions[0] + Math.Abs(latitude)) * Math.Sign(latitude); fractions[1] = (fractions[1] + Math.Abs(longitude)) * Math.Sign(longitude); var result = from f in fractions select f.ToString("F5"); return(result.ToArray()); }
public static async Task <string> GetDowJonesAsync(GDate gdate) { // http://geo.crox.net/djia/%Y/%m/%d // According to the W30 rule, use actual date or date before, depending on date and longitude var result = await httpClient.GetAsync($"http://geo.crox.net/djia/{gdate.DowJonesString()}"); if (!result.IsSuccessStatusCode) { return(""); } var data = await result.Content.ReadAsStringAsync(); return(data); }