/// <summary> /// Parses the ongoing resource transits in the market. /// </summary> /// <param name="htmlDoc">Html</param> public static List <MerchantsUnderWay> ParseTransits(HtmlAgilityPack.HtmlDocument htmlDoc) { var formulat = htmlDoc.GetElementbyId("merchantsOnTheWay"); var underWay = new List <MerchantsUnderWay>(); TransitType transitType = default; foreach (var child in formulat.ChildNodes) { if (child.HasClass("spacer")) { transitType = Localizations.MercahntDirectionFromString(child.InnerText); continue; } else if (child.HasClass("traders")) { underWay.Add(new MerchantsUnderWay() { Arrival = DateTime.Now.Add(TimeParser.ParseTimer(child)), TargetVillageId = (int)Parser.RemoveNonNumeric(child.Descendants("td").First(x => x.HasClass("dorf")).Descendants("a").First().GetAttributeValue("href", "")), RepeatTimes = (int)Parser.RemoveNonNumeric(child.Descendants("div").First(x => x.HasClass("repeat")).InnerText), Transit = transitType, Resources = ResourceParser.ParseResourcesMerchants(child), }); } } return(underWay); }
public Schema(JObject jsonSchema) { Description = jsonSchema.Value <string>("description"); var type = jsonSchema.Value <string>("type"); TransitType = (TransitType)Enum.Parse(typeof(TransitType), type); switch (TransitType) { case TransitType.Dictionary: { var properties = jsonSchema.Value <JObject>("properties"); foreach (var kvp in properties) { var name = kvp.Key; var value = new Schema((JObject)kvp.Value); children.Add(name, value); } break; } case TransitType.Array: { var items = jsonSchema.Value <JObject>("items"); var arraySchema = new Schema(items); children.Add("array", arraySchema); break; } default: break; } }
/// <summary> /// Required for boarding passes; otherwise not allowed. Type of transit. /// </summary> public static PassBuilder.StyleBuilder TransitType(this PassBuilder.StyleBuilder builder, TransitType value) { builder.SetStyleValue(PassBuilder.GetCaller(), value.ToPassKitString()); return(builder); }
public BoardingPassStyle(TransitType transitType) : base() { this.TransitType = transitType; }
/// <summary> /// Method that calculates the actual time of transit /// </summary> /// <param name="latitude">Latitude value</param> /// <param name="longitude">Longitude value</param> /// <param name="currentTime">Day of calculation</param> /// <param name="type">Transit type</param> /// <returns>Time of transit</returns> private static DateTime TransitTime(double latitude, double longitude, DateTime currentTime, TransitType type) { // See algorithm from http://williams.best.vwh.net/sunrise_sunset_algorithm.htm // 1. first calculate the day of the year int dayOfYear = currentTime.DayOfYear; // 2. convert the longitude to hour value and calculate an approximate time int longitudeHour = (int)Math.Round(longitude / 15); int approxTime = 0; if (type == TransitType.Sunrise) { approxTime = dayOfYear + ((6 - longitudeHour) / 24); } else { approxTime = dayOfYear + ((18 - longitudeHour) / 24); } // 3. calculate the Sun's mean anomaly double meanAnomoly = (0.9856 * approxTime) - 3.289; // 4. calculate the Sun's true longitude double sunLongitude = meanAnomoly + (1.916 * Math.Sin(DegreesToRadians(meanAnomoly))) + (0.020 * Math.Sin(DegreesToRadians(2 * meanAnomoly))) + 282.634; sunLongitude = sunLongitude % 360.0; // 5a. calculate the Sun's right ascension double rightAscension = RadiansToDegrees(Math.Atan(0.91764 * Math.Tan(DegreesToRadians(sunLongitude)))) % 360.0; // 5b. right ascension value needs to be in the same quadrant as L double longitudeQuadrant = Math.Floor(sunLongitude / 90) * 90; double rightAscensionQuadrant = Math.Floor(rightAscension / 90) * 90; rightAscension = rightAscension + (longitudeQuadrant - rightAscensionQuadrant); // 5c. right ascension value needs to be converted into hours rightAscension = rightAscension / 15; // 6. calculate the Sun's declination double sinDec = 0.39782 * Math.Sin(DegreesToRadians(sunLongitude)); double cosDec = Math.Cos(Math.Asin(sinDec)); // 7a. calculate the Sun's local hour angle double zenith = 90.87; double cosH = (Math.Cos(DegreesToRadians(zenith)) - (sinDec * Math.Sin(DegreesToRadians(latitude)))) / (cosDec * Math.Cos(DegreesToRadians(latitude))); // handle where sun never sets or rises if (cosH > 1 || cosH < -1) { return ConvertOffsetToDateTime(currentTime, 0); } // 7b. finish calculating H and convert into hours double hours = 0.0; if (type == TransitType.Sunrise) { hours = 360.0 - RadiansToDegrees(Math.Acos(cosH)); } else { hours = RadiansToDegrees(Math.Acos(cosH)); } hours = hours / 15.0; // 8. calculate local mean time of rising/setting double time = hours + rightAscension - (0.06571 * approxTime) - 6.622; // 9. adjust back to UTC double universalTime = (time - longitudeHour) % 24.0; return ConvertOffsetToDateTime(currentTime, universalTime); }