protected override async Task ExecuteAsync(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { Task task = Task.Run(async() => { //try //{ Context = new ValourDB(ValourDB.DBOptions); if (Context != null && System.Diagnostics.Debugger.IsAttached == false) { stats.Time = DateTime.UtcNow; stats.userCount = Context.Users.Count(); stats.planetCount = Context.Planets.Count(); stats.planetmemberCount = Context.PlanetMembers.Count(); stats.channelCount = Context.PlanetChatChannels.Count(); stats.categoryCount = Context.PlanetCategories.Count(); await Context.Stats.AddAsync(stats); await Context.SaveChangesAsync(); stats = new StatObject(); _logger.LogInformation($"Saved successfully."); } }); while (!task.IsCompleted) { _logger.LogInformation($"Stat Worker running at: {DateTimeOffset.Now}"); await Task.Delay(60000, stoppingToken); } _logger.LogInformation("Stat Worker task stopped at: {time}", DateTimeOffset.Now); _logger.LogInformation("Restarting.", DateTimeOffset.Now); } }
public static void UpdateSuffocation(Player __instance) { cfg = Config.GetConfig(); saveData = SaveData.GetSaveData(); StatObject stat = new StatObject() { Name = "Suffocation Time", Level = saveData.SuffocateResistLevel, MaxLevel = cfg.MaxSuffocateResistLevel, XP = saveData.SuffocateResist_XP, XPToNextLevel = saveData.SuffocateResist_XPToNextLevel, Modifier = cfg.SuffocateResist_XPNextLevel_Multiplier }; if (!StatMgr.CanLevelUp(stat)) { __instance.suffocationTime = 8 + saveData.SuffocateResistLevel; return; } int gainedLevels = StatMgr.DoWhileLevelUp(stat); Notify_LevelUp(stat, gainedLevels, stat.Level); saveData.SuffocateResistLevel = stat.Level; saveData.SuffocateResist_XP = stat.XP; saveData.SuffocateResist_XPToNextLevel = stat.XPToNextLevel; __instance.suffocationTime = 8 + saveData.SuffocateResistLevel; }
private void UpdateWalkSpeed() { var __instance = Player.main.playerController; StatObject stat = new StatObject() { Name = "Walk Speed", Level = saveData.WalkSpeedLevel, MaxLevel = cfg.MaxWalkSpeedLevel, XP = saveData.WalkSpeed_XP, XPToNextLevel = saveData.WalkSpeed_XPToNextLevel, Modifier = cfg.Walk_XPNextLevel_Multiplier }; if (!StatMgr.CanLevelUp(stat)) { UpdatePlayerController(__instance.groundController, saveData.WalkSpeedLevel); return; } int gainedLevels = StatMgr.DoWhileLevelUp(stat); StatMgr.NotifyLevelUp(stat, gainedLevels); saveData.WalkSpeedLevel = stat.Level; saveData.WalkSpeed_XP = stat.XP; saveData.WalkSpeed_XPToNextLevel = stat.XPToNextLevel; UpdatePlayerController(__instance.groundController, saveData.WalkSpeedLevel); }
public static float UpdateBreathPeriod(Player __instance, ref float __result) { saveData = SaveData.GetSaveData(); cfg = Config.GetConfig(); StatObject stat = new StatObject() { Name = "Breath Period", Level = saveData.BreathPeriodLevel, MaxLevel = cfg.MaxBreathPeriodLevel, XP = saveData.BreathPeriod_XP, XPToNextLevel = saveData.BreathPeriod_XPToNextLevel, Modifier = cfg.BreathPeriod_XPNextLevel_Multiplier }; if (!StatMgr.CanLevelUp(stat)) { __result += CalcBreathPeriodPercent(saveData.BreathPeriodLevel); return(__result); } int gainedLevels = StatMgr.DoWhileLevelUp(stat); Air.NotifyLevelUp(stat); saveData.BreathPeriodLevel = stat.Level; saveData.BreathPeriod_XP = stat.XP; saveData.BreathPeriod_XPToNextLevel = stat.XPToNextLevel; __result += CalcBreathPeriodPercent(saveData.BreathPeriodLevel); return(__result); }
//float defaultMaxHealth = 100f; public static void UpdateHealth(Player __instance) { saveData = SaveData.GetSaveData(); cfg = Config.GetConfig(); StatObject stat = new StatObject() { Name = "Max Health", Level = saveData.HealthLevel, MaxLevel = cfg.MaxHealthLevel, XP = saveData.Health_XP, XPToNextLevel = saveData.Health_XPToNextLevel, Modifier = cfg.Health_XPNextLevel_Multiplier }; if (!StatMgr.CanLevelUp(stat)) { __instance.liveMixin.data.maxHealth = 100 + saveData.HealthLevel; return; } int gainedLevels = StatMgr.DoWhileLevelUp(stat); StatMgr.NotifyLevelUp(stat, gainedLevels); saveData.HealthLevel = stat.Level; saveData.Health_XP = stat.XP; saveData.Health_XPToNextLevel = stat.XPToNextLevel; __instance.liveMixin.data.maxHealth = 100 + saveData.HealthLevel; }
private ActionResult stats(Guid gid) { var cx = SmartHomeDBContext.Create(AppSettings); var fromD = DateTime.Now.AddDays(-1); var toD = DateTime.Now; var firstlist = from s in cx.DeviceLogs where s.DeviceId == gid && s.Created > fromD && s.Created <= toD select s; var list = from s in firstlist.ToList() let groupKey = new DateTime(s.Created.Year, s.Created.Month, s.Created.Day, s.Created.Hour, (s.Created.Minute / 10) * 10, 0) group s by groupKey into g select new { Timestamp = g.Key, DogHouseHeat = g.Max(e => e.DogHouseHeatingOn), DogHouseTemp = g.Average(e => e.DogHouseTemperature), IsWet = g.Max(e => e.IsWet), WaterOn = g.Max(e => e.WaterOn), Temp = g.Average(e => e.Temperature) }; var finallist = list.OrderBy(e => e.Timestamp); var ret = new StatObject(); foreach (var i in finallist) { var itm = new StatItem(); itm.dogheating = i.DogHouseHeat; itm.dogtemp = i.DogHouseTemp; itm.iswet = i.IsWet; itm.temp = i.Temp; itm.time = MySmartHomeCore.Extensions.DateTimeUtil.GetZonedDate(i.Timestamp, "HH:mm"); itm.wateron = i.WaterOn; if (ret.min > itm.dogtemp) { ret.min = itm.dogtemp; } if (ret.min > itm.temp) { ret.min = itm.temp; } if (ret.max < itm.dogtemp) { ret.max = itm.dogtemp; } if (ret.max < i.Temp) { ret.max = itm.temp; } ret.items.Add(itm); } return(View(ret)); }
public static StatObject ReadLocalDBJson(string path) { var setting = new JsonSerializerSettings(); setting.Formatting = Newtonsoft.Json.Formatting.Indented; setting.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; setting.NullValueHandling = Newtonsoft.Json.NullValueHandling.Include; var fileContent = File.ReadAllText(path); StatObject mj = JsonConvert.DeserializeObject <StatObject>(fileContent); return(mj); }
public static void SaveToJson(StatObject mjb, string path) { JsonSerializer serializer = new JsonSerializer(); serializer.Converters.Add(new JavaScriptDateTimeConverter()); serializer.NullValueHandling = NullValueHandling.Ignore; using (StreamWriter sw = new StreamWriter(path)) using (JsonWriter writer = new JsonTextWriter(sw)) { serializer.Serialize(writer, mjb); // {"ExpiryDate":new Date(1230375600000),"Price":0} } }
public static void Notify_LevelUp(StatObject stat, int gainedLevels, float currentResistance) { System.Random random = new System.Random(); Suffocation s = new Suffocation(); StatMgr mgr = new StatMgr(); int responseNum = random.Next(0, s.Notifs.Count - 1); Logger.Log(String.Format(s.Notifs[responseNum], stat.Name, 8 + stat.Level)); if (stat.Level >= stat.MaxLevel) { int maxRandom = random.Next(0, mgr.maxLevelNotifs.Count - 1); Logger.Log(String.Format(mgr.maxLevelNotifs[maxRandom], stat.Name)); } }
public static void NotifyLevelUp(StatObject stat) { Random random = new Random(); Air a = new Air(); StatMgr mgr = new StatMgr(); int responseNum = random.Next(0, a.singleLevelNotifs.Count - 1); Logger.Log(String.Format(a.singleLevelNotifs[responseNum], stat.Name, CalcBreathPeriodPercent(stat.Level) + 3)); if (stat.Level >= stat.MaxLevel) { int maxRandom = random.Next(0, mgr.maxLevelNotifs.Count - 1); Logger.Log(String.Format(mgr.maxLevelNotifs[maxRandom], stat.Name) + ". Each breath now lasts " + (CalcBreathPeriodPercent(stat.Level) + 3) + " seconds"); } }
void Start() { string localDBPath = Path.Combine(Application.streamingAssetsPath, "LocalDB.json"); StatObject so = MultiplayerManager.ReadLocalDBJson(localDBPath); float winrate; float averageTime; float averageOrders; if (so.totalGames != 0 && so.wonGames != 0) { winrate = so.wonGames / so.totalGames * 100; averageTime = so.totalSeconds / so.wonGames; averageOrders = so.totalOrders / so.wonGames; } else { winrate = 0; averageTime = 0; averageOrders = 0; } if (winrate < 50) { percentage.color = Color.red; } percentage.text = string.Format("{0:00.00}%", winrate); if (PlayerPrefs.GetString("English") == "true") { allTimeLabel.text = "Win rate:"; averageTimes.text = string.Format("Average time needed to provide a solution: {0:0.00}s\nAverage orders needed to provide a solution: {1:0}", averageTime, averageOrders); } else { allTimeLabel.text = "Отношение печалба:"; averageTimes.text = string.Format("Средно време за решение: {0:0.00}s\nСреден брой команди: {1:0}", averageTime, averageOrders); } }
public Enemy(int x, int y, int width, int height, Rectangle rectSect, Color color, Game game, float layerDepth) { Counter++; target = null; this.x = x; this.y = y; this.widthX = width; this.heightY = height; this.type = ENEMY_ID; this.sightRange = 290f; this.objectInfo = "enemy"; this.setSolid(true); this.isChasing = false; this.init(x, y, width, height, rectSect, color, game, layerDepth, type, true); this.FrameNumber = 6; this.game = game; this.setTexture("Alex_Left_Idle"); this.lastPosition = LEFT; count = 0; attackCounter = 0; this.MaxHealth = 50; }
/// <summary> /// Gets the statistics. /// </summary> /// <param name="sessionID">The sessionID of the current session</param> /// <param name="stat">The stat.</param> /// <param name="typeOfStat">The type of stat.</param> /// <param name="productID">The product ID.</param> /// <param name="start">The start date and time </param> /// <param name="end">The end date and time</param> /// <returns></returns> public List<double> GetStatistics(string sessionID, StatObject stat, StatType typeOfStat, int productID, DateTime start, DateTime end) { if (stat == StatObject.Income) { if (typeOfStat == StatType.ForEachDay) { BillItemsTableAdapter bia = new BillItemsTableAdapter(); CustomerTransactionsTableAdapter cta = new CustomerTransactionsTableAdapter(); var transactions = cta.GetDataByTimeFrame(start, end); int numOfDays = (int)(end.Date.Subtract(start.Date).TotalDays); double[] re = new double[numOfDays+1]; foreach (var trans in transactions) { if (!trans.IsEndTimeNull()) { int dayVal = (int)(trans.EndTime.Date.Subtract(start.Date).TotalDays); var bills = bia.GetDataByWorkflowID(trans.WorkflowInstID); re[dayVal] += (double)(from p in bills select p.Price).Sum(); } } return re.ToList(); } } else if (stat == StatObject.PayroleExpence) { if (typeOfStat == StatType.ForEachDay) { WorkerShiftsTableAdapter wta = new WorkerShiftsTableAdapter(); var shifts = wta.GetDataByTimeFrame(start, end); int numOfDays = (int)(end.Date.Subtract(start.Date).TotalDays); RolePayrateTableAdapter rta = new RolePayrateTableAdapter(); var payoutTable = rta.GetData(); List<double> re = new List<double>(); DateTime i_start = start.Date; DateTime i_end = i_start.Add(new TimeSpan(1, 0, 0, 0)); for (int i = 0; i < numOfDays; i++) { decimal v = (from p in shifts where p.StartTime > i_start && p.StartTime < i_end && p.IsEndTimeNull() == false select (from q in payoutTable where q.Role == p.Role select q.PayPerHour).FirstOrDefault() * (decimal)(p.EndTime.Subtract(p.StartTime).TotalHours)).Sum(); re.Add((double)v); i_start = i_end; i_end = i_start.Add(new TimeSpan(1, 0, 0, 0)); } return re; } } return null; }
public void setTarget(StatObject target) { currentTarget = target; }
public void ShowWinner() { var allMM = FindObjectsOfType <MultiplayerManager>(); print(allMM.Length); StartCoroutine(DownloadDataFromTheSerer()); foreach (var item in allMM) { if (item.resultPanel != null) { resultPanel = item.resultPanel; } } resultPanel.SetActive(true); SpriteManager sm = FindObjectOfType <SpriteManager>(); MJ mjb = ReadJson(jsonPath); string winner = ""; int max = 0; switch (PlayerPrefs.GetString("diff")) { case "easy": foreach (var item in mjb.Players) { if (item.AmountOfBlueTilesEnlightened >= max) { max = item.AmountOfBlueTilesEnlightened; winner = item.Nickname; } } foreach (var item in mjb.Players) { if (item.Nickname == username) { item.showed = true; break; } } break; case "hard": foreach (var item in mjb.PlayersHard) { if (item.AmountOfBlueTilesEnlightened >= max) { max = item.AmountOfBlueTilesEnlightened; winner = item.Nickname; } } foreach (var item in mjb.PlayersHard) { if (item.Nickname == username) { item.showed = true; break; } } break; default: break; } SaveToJson(mjb, jsonPath); PlayerProfile winnerProfile = new PlayerProfile(); PlayerProfile secondPlaceProfile = new PlayerProfile(); switch (PlayerPrefs.GetString("diff")) { case "easy": if (mjb.Players.Count == 2) { if (mjb.Players[0].Nickname == winner) { if (mjb.Players[0].AmountOfBlueTilesEnlightened == mjb.Players[1].AmountOfBlueTilesEnlightened) { if (mjb.Players[0].AmountOfOrders > mjb.Players[1].AmountOfOrders) { winnerProfile = mjb.Players[1]; secondPlaceProfile = mjb.Players[0]; } else if (mjb.Players[0].AmountOfOrders == mjb.Players[1].AmountOfOrders) { if (mjb.Players[0].timeInSeconds > mjb.Players[1].timeInSeconds) { winnerProfile = mjb.Players[1]; secondPlaceProfile = mjb.Players[0]; } else { winnerProfile = mjb.Players[0]; secondPlaceProfile = mjb.Players[1]; } } else { winnerProfile = mjb.Players[0]; secondPlaceProfile = mjb.Players[1]; } } else { winnerProfile = mjb.Players[0]; secondPlaceProfile = mjb.Players[1]; } } else if (mjb.Players[1].Nickname == winner) { if (mjb.Players[1].AmountOfBlueTilesEnlightened == mjb.Players[0].AmountOfBlueTilesEnlightened) { if (mjb.Players[1].AmountOfOrders > mjb.Players[0].AmountOfOrders) { winnerProfile = mjb.Players[0]; secondPlaceProfile = mjb.Players[1]; } else if (mjb.Players[1].AmountOfOrders == mjb.Players[0].AmountOfOrders) { if (mjb.Players[1].timeInSeconds > mjb.Players[0].timeInSeconds) { winnerProfile = mjb.Players[0]; secondPlaceProfile = mjb.Players[1]; } else { winnerProfile = mjb.Players[1]; secondPlaceProfile = mjb.Players[0]; } } else { winnerProfile = mjb.Players[1]; secondPlaceProfile = mjb.Players[0]; } } else { winnerProfile = mjb.Players[1]; secondPlaceProfile = mjb.Players[0]; } } } break; case "hard": if (mjb.PlayersHard[0].Nickname == winner) { if (mjb.PlayersHard[0].Nickname == winner) { if (mjb.PlayersHard[0].AmountOfBlueTilesEnlightened == mjb.PlayersHard[1].AmountOfBlueTilesEnlightened) { if (mjb.PlayersHard[0].AmountOfOrders > mjb.PlayersHard[1].AmountOfOrders) { winnerProfile = mjb.PlayersHard[1]; secondPlaceProfile = mjb.PlayersHard[0]; } else if (mjb.PlayersHard[0].AmountOfOrders == mjb.PlayersHard[1].AmountOfOrders) { if (mjb.PlayersHard[0].timeInSeconds > mjb.PlayersHard[1].timeInSeconds) { winnerProfile = mjb.PlayersHard[1]; secondPlaceProfile = mjb.PlayersHard[0]; } else { winnerProfile = mjb.PlayersHard[0]; secondPlaceProfile = mjb.PlayersHard[1]; } } else { winnerProfile = mjb.PlayersHard[0]; secondPlaceProfile = mjb.PlayersHard[1]; } } else { winnerProfile = mjb.PlayersHard[0]; secondPlaceProfile = mjb.PlayersHard[1]; } } } else if (mjb.PlayersHard[1].Nickname == winner) { if (mjb.PlayersHard[1].AmountOfBlueTilesEnlightened == mjb.PlayersHard[0].AmountOfBlueTilesEnlightened) { if (mjb.PlayersHard[1].AmountOfOrders > mjb.PlayersHard[0].AmountOfOrders) { winnerProfile = mjb.PlayersHard[0]; secondPlaceProfile = mjb.PlayersHard[1]; } else if (mjb.PlayersHard[1].AmountOfOrders == mjb.PlayersHard[0].AmountOfOrders) { if (mjb.PlayersHard[1].timeInSeconds > mjb.PlayersHard[0].timeInSeconds) { winnerProfile = mjb.PlayersHard[0]; secondPlaceProfile = mjb.PlayersHard[1]; } else { winnerProfile = mjb.PlayersHard[1]; secondPlaceProfile = mjb.PlayersHard[0]; } } else { winnerProfile = mjb.PlayersHard[1]; secondPlaceProfile = mjb.PlayersHard[0]; } } else { winnerProfile = mjb.PlayersHard[1]; secondPlaceProfile = mjb.PlayersHard[0]; } } break; } if (PlayerPrefs.GetString("English") == "true") { resultsLabel.text = "Results"; resultsOk.text = "Ok"; sm.winnerNameLabel.text = "Winner:\n" + winnerProfile.Nickname; sm.winnerData.text = string.Format("Amount of blue tiles enlighted: {0}\nAmount of orders used: {1}\nNeeded time to solve: {2} seconds", winnerProfile.AmountOfBlueTilesEnlightened, winnerProfile.AmountOfOrders, winnerProfile.timeInSeconds); sm.secondPlaceNameLabel.text = "Second place:\n" + secondPlaceProfile.Nickname; sm.secondPlaceData.text = string.Format("Amount of blue tiles enlighted: {0}\nAmount of orders used: {1}\nNeeded time to solve: {2} seconds", secondPlaceProfile.AmountOfBlueTilesEnlightened, secondPlaceProfile.AmountOfOrders, secondPlaceProfile.timeInSeconds); } else { resultsLabel.text = "Резултати"; resultsOk.text = "Окей"; sm.winnerNameLabel.text = "Победител:\n" + winnerProfile.Nickname; sm.winnerData.text = string.Format("Осветени полета: {0}\nБрой използвани команди: {1}\nНужно време за решаване: {2} секунди", winnerProfile.AmountOfBlueTilesEnlightened, winnerProfile.AmountOfOrders, winnerProfile.timeInSeconds); sm.secondPlaceNameLabel.text = "Губещ:\n" + secondPlaceProfile.Nickname; sm.secondPlaceData.text = string.Format("Осветени полета: {0}\nБрой използвани команди: {1}\nНужно време за решаване: {2} секунди", secondPlaceProfile.AmountOfBlueTilesEnlightened, secondPlaceProfile.AmountOfOrders, secondPlaceProfile.timeInSeconds); } // Gathering the data for the local Database string localDB = Path.Combine(Application.streamingAssetsPath, "LocalDB.json"); StatObject so = ReadLocalDBJson(localDB); so.totalGames++; // Adding data for the statistics if (winnerProfile.Nickname == username) { so.wonGames++; so.totalSeconds = winnerProfile.timeInSeconds; so.totalOrders = winnerProfile.AmountOfOrders; } // Saving the data in the local db json file SaveToJson(so, localDB); print(winnerProfile.Nickname + " is the fuckign winner with " + winnerProfile.AmountOfBlueTilesEnlightened); sm.place1.sprite = sm.ReturnAvatar(winnerProfile); sm.place2.sprite = sm.ReturnAvatar(secondPlaceProfile); showWinner = false; UploadInServer(); }
public void setTarget(StatObject go) { target = go; }