public float AvarageRating(int?id) { Astro model = db.Astroes.Find(id); if (model != null) { model.RatingsAstro = db.RatingAstroes .Where(r => r.AstroID == id).ToList(); float srednia = 0; int count = 0; if (model.RatingsAstro != null) { foreach (var ocena in model.RatingsAstro) { srednia = ocena.Number + srednia; count++; } } if (count != 0) { srednia = srednia / count; } return(srednia); } return(0); }
public IEnumerator UseDesant(Skill skill) { bool cdEnd = true; while (cdEnd == true && !isBroken) { int skill_cooldown = skill.SkillCoolDown; Astro Astro1 = (Astro)Instantiate(AstroPrefab, firepoint.transform.position, Quaternion.identity); Astro Astro2 = (Astro)Instantiate(AstroPrefab, firepoint.transform.position, Quaternion.identity); Astro Astro3 = (Astro)Instantiate(AstroPrefab, firepoint.transform.position, Quaternion.identity); Astro1.PlayerShot = false; Astro2.PlayerShot = false; Astro3.PlayerShot = false; StartCoroutine(Astro1.Astro1(Player)); StartCoroutine(Astro2.Astro2(Player)); StartCoroutine(Astro3.Astro3(Player)); cdEnd = false; yield return(new WaitForSecondsRealtime(skill_cooldown)); cdEnd = true; } }
public ActionResult AddRating(int id) { Astro model = db.Astroes.Find(id); string title = model.Name; var routeValue = new RouteValueDictionary (new { action = "Create", controller = "RatingAstro", id, title }); return(RedirectToRoute(routeValue)); }
public void Use(GameObject whouse) { Astro Astro1 = (Astro)Instantiate(AstroPrefab, firepoint.transform.position, Quaternion.identity); Astro Astro2 = (Astro)Instantiate(AstroPrefab, firepoint2.transform.position, Quaternion.identity); Astro Astro3 = (Astro)Instantiate(AstroPrefab, firepoint3.transform.position, Quaternion.identity); StartCoroutine(Astro1.Astro1(Enemy)); StartCoroutine(Astro2.Astro2(Enemy)); StartCoroutine(Astro3.Astro3(Enemy)); }
//Convert.ToSingle(info needed to be changed to float or w/e num type) public WeatherViewModel(ForecastDay forecastDay, Astro astro, Condition condition, Condition2 condition2, Day day, Hour hour, Location location, Forecast forecast) { DailyMaxTemp = forecastDay.Day.MaxTempF; DailyMinTemp = forecastDay.Day.MinTempF; DailyAvgTemp = forecastDay.Day.AvgTempF; MaxWind = hour.WindMph; TotalPrecip = hour.PrecipMm; AvgHumidity = day.AvgHumidity; Hours = forecastDay.Hour.ToList(); }
public BaseCalc(Astro astro, int position) { this.selectedAstro = astro; this.metal = selectedAstro.Metal; this.gas = selectedAstro.Gas; this.crystals = selectedAstro.Crystals; this.fertility = selectedAstro.Fertility; this.area = selectedAstro.Area; this.position = position; //Code ommited }
public ActionResult DeleteConfirmed(int id) { try { Astro model = db.Astroes.Find(id); db.Astroes.Remove(model); db.SaveChanges(); } catch (DataException /* dex */) { //Log the error (uncomment dex variable name and add a line here to write a log. return(RedirectToAction("Delete", new { id = id, saveChangesError = true })); } return(RedirectToAction("Index")); }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Space)) { Astro temp = Instantiate(astroRef, 18 * Random.insideUnitSphere + center.transform.position, Quaternion.identity).GetComponent <Astro>(); temp.dir = Random.Range(2, 10) * Vector3.Cross(center.transform.position, temp.transform.position).normalized *dir; if (dir == 1) { dir = -1; } else { dir = 1; } } }
// GET: Astro/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Astro model = db.Astroes.Find(id); ViewBag.Data = model.SendDate; ViewBag.ProfileId = model.ProfileID; if (model == null) { return(HttpNotFound()); } return(View(model)); }
// GET: Astro/Delete/5 public ActionResult Delete(int?id, bool?saveChangesError = false) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (saveChangesError.GetValueOrDefault()) { ViewBag.ErrorMessage = "Delete failed. Try again, and if the problem persists see your system administrator."; } Astro model = db.Astroes.Find(id); if (model == null) { return(HttpNotFound()); } return(View(model)); }
// GET: Astro/Details/5 public ActionResult Details(int?id) { if (AvarageRating(id).Equals("0")) { ViewBag.srednia = "Nie otrzymał jeszcze żadnej oceny."; } else { ViewBag.srednia = AvarageRating(id).ToString(); } if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Astro model = db.Astroes.Find(id); var astroKoments = db.AstroKoments .Where(a => a.AstroID == id).ToList(); foreach (var item in astroKoments) { var profile = db.Profiles .Where(mk => mk.Id == item.ProfileID).FirstOrDefault(); item.Profile = profile; } model.RatingsAstro = db.RatingAstroes .Where(r => r.AstroID == id).ToList(); foreach (var item in model.RatingsAstro) { item.Profile = db.Profiles .Where(p => p.Id == item.ProfileID).FirstOrDefault(); } if (model == null) { return(HttpNotFound()); } model.Profile = db.Profiles.Find(model.ProfileID); return(View(model)); }
private bool collisionAstros(Astro other) { if (Vector3.Distance(gameObject.transform.position, other.transform.position) <= cl.radius + other.cl.radius) { if (mass > other.mass) { dir += other.dir * other.Mass / mass; mass += other.mass; transform.localScale += Vector3.one * 0.05f * other.mass; Destroy(other.gameObject); } else { other.dir += dir * mass / other.mass; other.mass += mass; other.transform.localScale += Vector3.one * 0.05f * mass; Destroy(gameObject); } return(false); } return(true); }
public ActionResult Create([Bind(Include = "ID,Name,Description")] Astro model) { //string pom = ""; //List<string> pictures = new List<string>(); try { model.SendDate = DateTime.Now; HttpPostedFileBase file = Request.Files["PlikZeZdjeciem"]; if (file != null && file.ContentLength > 0) { model.Picture = System.Guid.NewGuid().ToString() + ".JPEG"; //Image.FromFile(file.FileName).Save ("jpg"); file.SaveAs(HttpContext.Server.MapPath("~/Zdjecia/") + model.Picture); } foreach (var profil in db.Profiles) { if (profil.UserName.Equals(User.Identity.Name)) { model.Profile = profil; } } if (ModelState.IsValid) { db.Astroes.Add(model); db.SaveChanges(); return(RedirectToAction("Index")); } } catch (DataException /* dex */) { //Log the error (uncomment dex variable name and add a line here to write a log. ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } return(View(model)); }
public ActionResult Edit([Bind(Include = "ID, ProfileID,Name,Description,SendDate")] Astro model) { if (ModelState.IsValid) { try { Astro model2 = db.Astroes.Find(model.ID); // .Where(m => m.ID == model.ID).find; HttpPostedFileBase file = Request.Files["PlikZeZdjeciem"]; if (file.FileName != "") { if (file != null && file.ContentLength > 0) { model.Picture = System.Guid.NewGuid().ToString() + ".JPEG"; //Image.FromFile(file.FileName).Save ("jpg"); if (model.Picture != model2.Picture) { file.SaveAs(HttpContext.Server.MapPath("~/Zdjecia/") + model.Picture); } } } if (file.FileName == "") { model.Picture = model2.Picture; } db.Entry(model).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } catch (DataException /* dex */) { //Log the error (uncomment dex variable name and add a line here to write a log. ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator."); } } return(View(model)); }
internal static void UpDateForecasts(IEnumerable <ForecastFromSource> latestForecastsFromSource, IEnumerable <DailyIcon> dailyIcons) { DateTime fullHours = DateTime.Today.AddHours(DateTime.Now.Hour); try { using (WeatherContext db = new WeatherContext()) { WeatherSource[] source = latestForecastsFromSource.Select(x => x.source).Distinct().ToArray(); foreach (var s in source) { db.WeatherSources.Attach(s); } // Group ratings by the farness of the forecast var result = from f in db.Ratings group f by DbFunctions.DiffHours(f.ForecastDate, f.ForecastFor).HasValue ? DbFunctions.DiffHours(f.ForecastDate, f.ForecastFor).Value : 0 into g//farness select g; result.ToList(); //select best ratings by farness var topOfRatings = (from g in result select new { airTemperature = (from p in g group p.AirTemperature by p.Source into gr select new { val = gr.Sum(), source = gr.Key }).OrderByDescending(x => x.val).FirstOrDefault().source, iconDescription = (from p in g group p.WeatherDescription by p.Source into gr select new { val = gr.Sum(), source = gr.Key }).OrderByDescending(x => x.val).FirstOrDefault().source, pressure = (from p in g group p.Pressure by p.Source into gr select new { val = gr.Sum(), source = gr.Key }).OrderByDescending(x => x.val).FirstOrDefault().source, humidity = (from p in g group p.Humidity by p.Source into gr select new { val = gr.Sum(), source = gr.Key }).OrderByDescending(x => x.val).FirstOrDefault().source, WindSpeed = (from p in g group p.WindSpeed by p.Source into gr select new { val = gr.Sum(), source = gr.Key }).OrderByDescending(x => x.val).FirstOrDefault().source, WindDirection = (from p in g group p.WindDirection by p.Source into gr select new { val = gr.Sum(), source = gr.Key }).OrderByDescending(x => x.val).FirstOrDefault().source, Fallout = (from p in g group p.Fallout by p.Source into gr select new { val = gr.Sum(), source = gr.Key }).OrderByDescending(x => x.val).FirstOrDefault().source, Snow = (from p in g group p.Snow by p.Source into gr select new { val = gr.Sum(), source = gr.Key }).OrderByDescending(x => x.val).FirstOrDefault().source, Cloud = (from p in g group p.Cloud by p.Source into gr select new { val = gr.Sum(), source = gr.Key }).OrderByDescending(x => x.val).FirstOrDefault().source, Farness = g.Key }).AsEnumerable(); // database query ends here, the rest is a query in memory var resultForecast = (from rat in topOfRatings// select forecasts by best ratings select new { rating = rat, forecastse = (from lf in latestForecastsFromSource where fullHours.AddHours(rat.Farness) == lf.date select lf).ToList() }).AsEnumerable(); IEnumerable <WeatherCondition> res = new List <WeatherCondition>(); try { res = from obj in resultForecast where obj.forecastse.Count > 0 select new WeatherCondition { date = fullHours.AddHours(obj.rating.Farness), airTemperature = obj.forecastse.Where(x => x.source == obj.rating.airTemperature).FirstOrDefault().airTemperature, isDay = obj.forecastse.Where(x => x.source == obj.rating.iconDescription).FirstOrDefault().isDay, description = obj.forecastse.Where(x => x.source == obj.rating.iconDescription).FirstOrDefault().description, pressure = obj.forecastse.Where(x => x.source == obj.rating.pressure).FirstOrDefault().pressure, humidity = obj.forecastse.Where(x => x.source == obj.rating.humidity).FirstOrDefault().humidity, windSpeed = obj.forecastse.Where(x => x.source == obj.rating.WindSpeed).FirstOrDefault().windSpeed, windDirection = obj.forecastse.Where(x => x.source == obj.rating.WindDirection).FirstOrDefault().windDirection, rain = obj.forecastse.Where(x => x.source == obj.rating.Fallout).FirstOrDefault().rain, snow = obj.forecastse.Where(x => x.source == obj.rating.Snow).FirstOrDefault().snow, cloud = obj.forecastse.Where(x => x.source == obj.rating.Cloud).FirstOrDefault().cloud }; } catch (Exception ex) { Logger.Log.Error("", ex); } ///////////////////////////////////////////////////////////////////// code for description//////////////////////////////////////////////////// var TopOfDescriptionRating = from g in topOfRatings select new { date = fullHours.AddHours(g.Farness).Date, sourse = g.iconDescription }; var SourcesDescriptionRating = from g in TopOfDescriptionRating group g by g.date into gr select new { date = gr.Key, sourses = gr.GroupBy(x => x.sourse).OrderByDescending(x => x.Count()) }; var SourceDescriptionRating = from g in SourcesDescriptionRating select new { date = g.date, source = g.sourses.FirstOrDefault().Key }; ///////////////////////////////////////////////////////////////////// end code for description//////////////////////////////////////////////////// lock (LatestForecasts) { LatestForecasts.Clear(); // breakdown by day var resGroupByDay = from forecast in res group forecast by forecast.date.Date into forecastOnDay select forecastOnDay; foreach (var forecastsOnDay in resGroupByDay.OrderBy(x => x.Key)) { OneDayForecast f = new OneDayForecast(); f.date = forecastsOnDay.Key; f.astro = Astro.GetAstroByDate(forecastsOnDay.Key); WeatherSource oneDaySource = SourceDescriptionRating.Where(x => x.date == forecastsOnDay.Key).FirstOrDefault().source; f.description = dailyIcons.Where(x => x.forecastFor == forecastsOnDay.Key && x.source == oneDaySource).FirstOrDefault().description; f.Forecasts.AddRange(forecastsOnDay.OrderBy(x => x.date)); LatestForecasts.Add(f); } LatestForecastUpdate = DateTime.Now; } //delete old data from the table OneDayAnalyticForecast end WeatherCondition try { foreach (var forecast in db.OneDayAnalyticForecast.Include("Forecasts")) { db.WeatherConditions.RemoveRange(forecast.Forecasts); db.OneDayAnalyticForecast.Remove(forecast); } db.SaveChanges(); } catch (Exception ex) { Logger.Log.Error("An error occurred while trying to delete OneDayAnalyticForecast", ex); } try { var descriptions = LatestForecasts.Select(f => f.description).Distinct(); var icons = LatestForecasts.Select(f => f.description.Icon).Distinct(); var astros = LatestForecasts.Select(f => f.astro).Distinct(); foreach (var astro in astros) { if (astro != null) { if (db.Entry(astro).State == EntityState.Detached) { db.AstroByDays.Attach(astro); } } } foreach (var forecast in LatestForecasts) { foreach (var condition in forecast.Forecasts) { if (!descriptions.Contains(condition.description)) { if (db.Entry(condition.description).State == EntityState.Detached) { db.WeatherDescriptions.Attach(condition.description); } } if (!icons.Contains(condition.description.Icon)) { if (db.Entry(condition.description.Icon).State == EntityState.Detached) { db.WeatherIcons.Attach(condition.description.Icon); } } } foreach (var descript in descriptions) { if (db.Entry(descript).State == EntityState.Detached) { db.WeatherDescriptions.Attach(descript); } } foreach (var icon in icons) { if (db.Entry(icon).State == EntityState.Detached) { db.WeatherIcons.Attach(icon); } } } foreach (var forecast in LatestForecasts) { db.OneDayAnalyticForecast.Add(forecast); } db.SaveChanges(); } catch (Exception ex) { Logger.Log.Error("An error occurred while trying to save analytic forecasts in AnalyticForecastFactory", ex); } } } catch (Exception ex) { Logger.Log.Error("An error occurred while trying to create analytic forecasts", ex); } }
private float CalcAtraction(Astro A, Astro B) { return(0.006f * B.Mass / Mathf.Pow(Vector3.Distance(A.transform.position, B.transform.position), 2)); }
public DailyForecast(Skycon skycon, Range temperature, Range humidity, Range precipitation, RangeWind wind, Astro astro) { CultureInfo provider = CultureInfo.InvariantCulture; Date = DateTime.ParseExact(temperature.date, "yyyy-MM-dd", provider); SunRise = TimeSpan.Parse(astro.sunrise.time); SunSet = TimeSpan.Parse(astro.sunset.time); Condition = new DailyCondition(skycon); HighTemp = Temperature.FromCelsius((float)temperature.max); LowTemp = Temperature.FromCelsius((float)temperature.min); Humidity = (uint)(humidity.avg * 100); Precipitation = (uint)precipitation.avg; Wind = new Wind(wind.avg); }