예제 #1
0
파일: GDate.cs 프로젝트: roseeng/GeoHash
        public static GDate ForGlobalhash(DateTime date)
        {
            // W30 adjustments
            var dowJonesDate = date.AddDays(-1);

            GDate inst = new GDate(date, dowJonesDate);

            return(inst);
        }
예제 #2
0
파일: GeoHash.cs 프로젝트: roseeng/GeoHash
        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);
        }
예제 #3
0
파일: GDate.cs 프로젝트: roseeng/GeoHash
        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);
        }
예제 #4
0
파일: GeoHash.cs 프로젝트: roseeng/GeoHash
        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);
        }
예제 #5
0
파일: GeoHash.cs 프로젝트: roseeng/GeoHash
        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());
        }
예제 #6
0
파일: GeoHash.cs 프로젝트: roseeng/GeoHash
        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);
        }