public void SetFrom(StatisticsSet other) { foreach (var lKey in other.mValuesByKey.Keys) { this.Set(lKey, other.GetDouble(lKey)); } }
public void IncrementFrom(StatisticsSet other) { foreach (var lKey in other.mValuesByKey.Keys) { this.IncrementFrom(other, lKey); } }
private void OnEnable() { this.PauseGame(); var lHiveController = FindObjectOfType <HiveController>(); var lPlayerController = FindObjectOfType <PlayerController>(); var lGameState = GameController.instance.GameState; var lDayStats = StatisticsSet.CreateEmpty(); lDayStats.Set(StatisticKeys.PollenPickupCount, lPlayerController.PollenPickupCount); lDayStats.Set(StatisticKeys.PollenCollected, lHiveController.CurrentPollen); lDayStats.Set(StatisticKeys.HiveDropOffCount, lHiveController.PollenDropOffCount); lDayStats.Set(StatisticKeys.RemainingPollen, lPlayerController.CurrentPollen); lDayStats.Set(StatisticKeys.TotalDistanceTraveled, lPlayerController.TotalDistanceTraveled); // TODO lDayStats.Set(StatisticKeys.TotalFlowersCollected, 0); lDayStats.Set(StatisticKeys.FurthestDistanceTraveled, 0); lGameState.FinializeDay(lDayStats); GameController.instance.Save(); this.AddFormField("Collected Pollen", lDayStats.GetString(StatisticKeys.PollenCollected, "0.00")); this.AddFormField("Salvaged Pollen", lDayStats.GetString(StatisticKeys.SalvagedPollen, "0.00")); this.AddFormField("Available Pollen", lGameState.Statistics.GetString(StatisticKeys.RemainingPollen, "0.00")); this.AddFormField("Batches Processed", lDayStats.GetString(StatisticKeys.HoneyBatchCount, "0.00")); this.AddFormField("Pollen Used", lDayStats.GetString(StatisticKeys.PollenProcessed, "0.00")); this.AddFormField("Honey Produced", lDayStats.GetString(StatisticKeys.HoneyProduced, "0.00")); this.AddFormField("Total Honey", lGameState.Statistics.GetString(StatisticKeys.HoneyAvailable, "0.00")); }
public static StatisticsSet CreateDefault() { var lSet = new StatisticsSet(); foreach (var lKey in sKeyArray) { lSet.mValuesByKey.Add(lKey, 0.0); } return(lSet); }
internal static StatisticsSet ToStatistics(this Newtonsoft.Json.Linq.JToken statPackage) { var set = new StatisticsSet(); foreach (var item in statPackage["values"]) { if (item.ParseStat(out (string key, string value)stat)) { set.AddStat(stat.key, stat.value); } // set.AddStat(item["name"]?.ToString() ?? item["altName"]?.ToString(), item["value"].ToString()); } return(set); }
public void FinializeDay(StatisticsSet dayStats) { this.Statistics.Increment(StatisticKeys.TotalDays); var lRemainingPollen = dayStats.GetDouble(StatisticKeys.RemainingPollen); var lCollectedPollen = dayStats.GetDouble(StatisticKeys.PollenCollected); var lSalvagedPollen = lRemainingPollen * this.Attributes.GetDouble(AttributeKeys.SalvageRate); var lTotalCollectedPollen = lCollectedPollen += lSalvagedPollen; this.Statistics.Increment(StatisticKeys.RemainingPollen, lTotalCollectedPollen); var lHoneyGenStats = this.Hive.GenerateHoney(this.Statistics, this.Attributes); this.Statistics.IncrementFrom(lHoneyGenStats); dayStats.SetFrom(lHoneyGenStats); dayStats.Set(StatisticKeys.SalvagedPollen, lSalvagedPollen); this.ChangeDayManager(); }
public StatisticsSet GenerateHoney(StatisticsSet stats, AttributeSet attributes) { var lPollenRequirement = attributes.GetDouble(AttributeKeys.PollenRequirement); var lMaximumBatchCount = Math.Floor(attributes.GetDouble(AttributeKeys.HoneyBatchCount)); var lTheoreticalBatchCount = Math.Floor(stats.GetDouble(StatisticKeys.RemainingPollen) / lPollenRequirement); var lBatchCount = (long)Math.Min(lMaximumBatchCount, lTheoreticalBatchCount); var lPollenRequired = lBatchCount * lPollenRequirement; var lHoneyGenerated = lBatchCount * attributes.GetDouble(AttributeKeys.HoneyYield); stats.Decrement(StatisticKeys.RemainingPollen, lPollenRequired); stats.Increment(StatisticKeys.HoneyAvailable, lHoneyGenerated); var lResult = StatisticsSet.CreateEmpty(); lResult.Set(StatisticKeys.HoneyBatchCount, lBatchCount); lResult.Set(StatisticKeys.PollenProcessed, lPollenRequired); lResult.Set(StatisticKeys.HoneyProduced, lHoneyGenerated); return(lResult); }
public static GameState CreateNew() { var lGameState = new GameState(); if (Debug.isDebugBuild) { lGameState.Seed = 42; } else { lGameState.Seed = Random.Range(int.MinValue, int.MaxValue); } lGameState.Attributes = new AttributeSet(); lGameState.World = WorldState.CreateNew(lGameState.Seed); lGameState.Hive = HiveState.CreateNew(); lGameState.Statistics = StatisticsSet.CreateDefault(); lGameState.Upgrades = UpgradeState.CreateNew(); lGameState.ChangeDayManager(); return(lGameState); }
public void IncrementFrom(StatisticsSet other, string key) { this.Set(key, other.GetDouble(key)); }
private byte[] CreateImage() { if (_tile.PresentationImage == null) { DisposeSurface(); } if (Surface == null) { return(null); } if (_refreshingClient) { return(GetCurrentTileBitmap()); } IImageSopProvider sop = _tile.PresentationImage as IImageSopProvider; if (sop != null) { //TODO (CR May 2010): sops are shared between users and threads. This will be an issue //for dynamic quality changes. DicomAttribute attrib = sop.ImageSop[DicomTags.LossyImageCompression]; DicomAttribute ratioAttrib = sop.ImageSop[DicomTags.LossyImageCompressionRatio]; bool lossy = false; if (_mimeType.Equals("image/jpeg")) { lossy = true; } if (lossy) { attrib.SetStringValue("01"); } else { if (ratioAttrib.IsEmpty) { attrib.SetEmptyValue(); } } } WebViewStudyStatistics stats = new WebViewStudyStatistics(_mimeType); //long t0 = Environment.TickCount; stats.DrawToBitmapTime.Start(); Bitmap bitmap = Bitmap; using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap)) { Surface.ContextID = graphics.GetHdc(); Surface.ClipRectangle = new Rectangle(0, 0, bitmap.Width, bitmap.Height); DrawArgs drawArgs = new DrawArgs(Surface, null, Rendering.DrawMode.Render); CurrentImage.Draw(drawArgs); drawArgs = new DrawArgs(Surface, null, Rendering.DrawMode.Refresh); CurrentImage.Draw(drawArgs); graphics.ReleaseHdc(Surface.ContextID); } stats.DrawToBitmapTime.End(); Bitmap bmp1 = null; if (DiagnosticsSettings.Default.CompareImageQuality) { // make a copy in case Bitmap.Save() has any side effects. bmp1 = (Bitmap)Bitmap.Clone(); } //TODO (CR May 2010): should be in using and/or closed. Separate function? MemoryStream ms = new MemoryStream(); _quality = _defaultJpegQFactor; if (_isMouseDown && IsDynamicImageQualityEnabled) { _quality = GetOptimalQFactor(Bitmap.Width, Bitmap.Height, sop); InitOrUpdateRefreshClientTimer(); } stats.SaveTime.Start(); if (_mimeType.Equals("image/jpeg")) { EncoderParameters eps = new EncoderParameters(1); eps.Param[0] = new EncoderParameter(Encoder.Quality, _quality); ImageCodecInfo ici = GetEncoderInfo(_mimeType); bitmap.Save(ms, ici, eps); } else if (_mimeType.Equals("image/png")) { bitmap.Save(ms, ImageFormat.Png); } stats.SaveTime.End(); byte[] imageBuffer = ms.ToArray(); if (Platform.IsLogLevelEnabled(LogLevel.Debug)) { Platform.Log(LogLevel.Debug, "Render Frame #{0}. Size= {1}bytes. Q={2} {3}. Highbit={4}", sop.ImageSop.InstanceNumber, imageBuffer.Length, _quality, _isMouseDown && IsDynamicImageQualityEnabled ? "[Dynamic]" : "", sop.Frame.HighBit); } ms.Position = 0; stats.ImageSize = (ulong)imageBuffer.LongLength; _stats.AddSubStats(stats); //StatisticsLogger.Log(LogLevel.Info, false, stats); if (_stats.SubStatistics.Count > 20) { _stats.CalculateAverage(); //StatisticsLogger.Log(LogLevel.Info, false, _stats); _stats = new StatisticsSet("AverageRender"); } //Console.WriteLine("Tile {0} : DrawToBitmap (size: {3}, mime: {2}):{1}ms", tile.Identifier,Environment.TickCount - t0,mimeType, ms.Length); //TODO (CR May 2010): #if DEBUG? if (DiagnosticsSettings.Default.CompareImageQuality) { Bitmap bmp2 = new Bitmap(ms); ImageComparisonResult result = BitmapComparison.Compare(ref bmp1, ref bmp2); //TODO (CR May 2010): ConsoleHelper Console.WriteLine("BMP vs {0} w/ client size: {1}x{2}", _mimeType, bmp2.Height, bmp2.Width); Console.WriteLine("\tR: MinError={2:0.00} MaxError={3:0.00} Mean={0:0.00} STD={1:0.00}", result.Channels[0].MeanError, result.Channels[0].StdDeviation, Math.Abs(result.Channels[0].MinError), Math.Abs(result.Channels[0].MaxError)); Console.WriteLine("\tG: MinError={2:0.00} MaxError={3:0.00} Mean={0:0.00} STD={1:0.00}", result.Channels[1].MeanError, result.Channels[1].StdDeviation, Math.Abs(result.Channels[1].MinError), Math.Abs(result.Channels[1].MaxError)); Console.WriteLine("\tB: MinError={2:0.00} MaxError={3:0.00} Mean={0:0.00} STD={1:0.00}", result.Channels[2].MeanError, result.Channels[2].StdDeviation, Math.Abs(result.Channels[2].MinError), Math.Abs(result.Channels[2].MaxError)); } return(imageBuffer); }