public void Test() { AnomalyDetectionAPI AnoDet_Api = new AnomalyDetectionAPI(null, 0); ClusteringSettings Settings; SaveLoadSettings SaveObject; SaveLoadSettings LoadObject; AnomalyDetectionResponse ImportData; //TODO: Remove user specific paths from application. string FilePath = @"C:\Users\mhoshen\Desktop\DataSet\SampleDataSet.csv"; double[][] RawData = Helpers.cSVtoDoubleJaggedArray(FilePath); string SavePath = @"C:\Users\mhoshen\Desktop\DataSet" + "json"; ImportData = SaveLoadSettings.JSON_Settings(SavePath, out SaveObject, true); string LoadimpPath = @"C:\Users\mhoshen\Desktop\DataSet" + ".json"; ImportData = SaveLoadSettings.JSON_Settings(LoadimpPath, out LoadObject, true); int kmeansMaxIterations = 5; int numClusters = 2; int numOfAttributes = 2; if (LoadimpPath.Contains("DataSet")) { Settings = new ClusteringSettings(RawData, kmeansMaxIterations, numClusters, numOfAttributes, SaveObject, Replace: true); } else { Settings = new ClusteringSettings(RawData, kmeansMaxIterations, numClusters, numOfAttributes, SaveObject, 1, false, LoadObject, Replace: true); } ImportData = AnoDet_Api.ImportNewDataForClustering(Settings); }
public void TestClusterCalcuation() { // // In test we know where are positions of centroids. // We will now create data around known centroids and let alorithm // find centroids. double[][] clusterCentars = new double[3][]; clusterCentars[0] = new double[] { 5.0, 5.0 }; clusterCentars[1] = new double[] { 15.0, 15.0 }; clusterCentars[2] = new double[] { 30.0, 30.0 }; string[] attributes = new string[] { "Height", "Weight" }; var rawData = Helpers.CreateSampleData(clusterCentars, 2, 10000, 0.5); int numAttributes = attributes.Length; // 2 in this demo (height,weight) int numClusters = 3; // vary this to experiment (must be between 2 and number data tuples) int maxCount = 300; // trial and error SaveLoadSettings persistenceProviderSettings; var resp = SaveLoadSettings.JSON_Settings("model.json", out persistenceProviderSettings, false); AnomalyDetectionAPI kmeanApi = new AnomalyDetectionAPI(rawData, numClusters); ClusteringSettings clusterSettings = new ClusteringSettings(rawData, maxCount, numClusters, numAttributes, persistenceProviderSettings, KmeansAlgorithm: 1, Replace: true); AnomalyDetectionResponse response = kmeanApi.ImportNewDataForClustering(clusterSettings); Assert.True(response.Code == 0); int detectedCluster; double[] Sample = new double[] { 26, 28 }; CheckingSampleSettings SampleSettings = new CheckingSampleSettings(null, Sample, 3); response = kmeanApi.CheckSample(SampleSettings, out detectedCluster); Assert.True(response.Code == 0); Assert.True(detectedCluster == 0); double[] Sample2 = new double[] { 150, 16 }; CheckingSampleSettings SampleSettings2 = new CheckingSampleSettings(null, Sample2, 3); response = kmeanApi.CheckSample(SampleSettings2, out detectedCluster); Assert.True(response.Code == 1); Assert.True(detectedCluster == -1);// Out of all clusters. double[] Sample3 = new double[] { 16, 14 }; CheckingSampleSettings SampleSettings3 = new CheckingSampleSettings(null, Sample3, 3); response = kmeanApi.CheckSample(SampleSettings3, out detectedCluster); Assert.True(response.Code == 0); Assert.True(detectedCluster == 1); double[] Sample4 = new double[] { 6, 4 }; CheckingSampleSettings SampleSettings4 = new CheckingSampleSettings(null, Sample4, 3); response = kmeanApi.CheckSample(SampleSettings4, out detectedCluster); Assert.True(response.Code == 0); Assert.True(detectedCluster == 2); }
void Start() { PlayerDataSettings loadedData = SaveLoadSettings.LoadPlayer(); music_selection = loadedData.music_vol_selection; effect_selection = loadedData.effect_vol_selection; Music_Box_Update(music_selection); Effect_Box_Update(effect_selection); }
public void SaveSettings() { // Save Settings PlayerDataSettings saveDataSettings = new PlayerDataSettings(); saveDataSettings.music_vol_selection = music_selection; saveDataSettings.effect_vol_selection = effect_selection; SaveLoadSettings.SavePlayer(saveDataSettings); }
public void ContinuousTrainData() { double[][] initialCentroids = new double[4][]; initialCentroids[0] = new double[] { 0.2, -4.0 }; initialCentroids[1] = new double[] { 0.2, -6.0 }; initialCentroids[2] = new double[] { 0.4, -4.0 }; initialCentroids[3] = new double[] { 0.4, -6.0 }; string[] attributes = new string[] { "x", "y" }; int numAttributes = attributes.Length; // 2 in this demo (x,y) int numClusters = 4; int maxCount = 300; SaveLoadSettings sett; var resp = SaveLoadSettings.JSON_Settings(@"C:\Data\Function1.json", out sett, true); AnomalyDetectionAPI kmeanApi = new AnomalyDetectionAPI(null, numClusters); LearningApi api = new LearningApi(loadMetaData1()); api.UseActionModule <object[][], object[][]>((input, ctx) => { var rawDatalist = getRealDataSample(@"C:\Data\Function1.csv").ToList(); double[][] oldSamples; var nn = kmeanApi.GetPreviousSamples(sett, out oldSamples); if (oldSamples != null) { foreach (var old in oldSamples) { var row = old.Cast <object>().ToArray(); rawDatalist.Add(row); } } return(rawDatalist.ToArray()); }); //this call must be first in the pipeline api.UseDefaultDataMapper(); api.UseGaussNormalizer(); var rawData = api.Run() as double[][]; Helpers.WriteToCSVFile(rawData); ClusteringSettings Settings = new ClusteringSettings(rawData, maxCount, numClusters, numAttributes, sett, KmeansAlgorithm: 1, InitialGuess: true, Replace: true); AnomalyDetectionResponse response = kmeanApi.ImportNewDataForClustering(Settings); }
public static void OpenWindow(ImplosiveExplosiveEditor newOwner) { owner = newOwner; opened = true; _saveLoadWindow = GetWindow <SaveLoadSettings>(); _saveLoadWindow.minSize = new Vector2(200, 250); _saveLoadWindow.maxSize = new Vector2(500, 600); StylePresets.CreateStyles(); }
/// <summary> /// SaveChecks is a function that checks the saving settings for errors. Some errors can be corrected. /// </summary> /// <param name="saveSettings">settings to save</param> /// <param name="settings">the checked settings to save</param> /// <returns>a code and a message that state whether the function succeeded or encountered an error. When the function succeeds, it will return: /// <ul style="list-style-type:none"> /// <li> - Code: 0, "OK" </li> /// </ul> /// </returns> public AnomalyDetectionResponse ValidateSaveConditions(SaveLoadSettings saveSettings, out SaveLoadSettings settings) { var adResponse = SaveLoadSettings.JsonSettings(saveSettings.ModelPath, out settings, saveSettings.Replace); if (adResponse.Code != 0) { settings = null; return(adResponse); } return(new AnomalyDetectionResponse(0, "OK")); }
public void Test_GetResults() { SaveLoadSettings persistenceProviderSettings; //For checking sample, file path should be Instace Result path var resp = SaveLoadSettings.JSON_Settings(@"C:\Data\Function1.json", out persistenceProviderSettings, false); AnomalyDetectionAPI kmeanApi = new AnomalyDetectionAPI(null, 0); ClusteringResults[] detectedCluster; var response = kmeanApi.GetResults(persistenceProviderSettings, out detectedCluster); Assert.True(response.Code == 0); }
/// <summary> /// Save is a function that saves an instance of AnomalyDetectionAPI. /// </summary> /// <param name="SaveObject">settings to save the AnomalyDetectionAPI instance</param> /// <param name="Instance">AnomalyDetectionAPI object to be saved</param> /// <returns>a code and a message that state whether the function succeeded or encountered an error. When the function succeeds, it will return: /// <ul style="list-style-type:none"> /// <li> - Code: 0, "OK" </li> /// </ul> /// </returns> public AnomalyDetectionResponse Save(SaveLoadSettings SaveObject, AnomalyDetectionAPI Instance) { try { //Directory.CreateDirectory(Path.GetDirectoryName(SaveObject.ModelPath)); FileStream fs = new FileStream(SaveObject.ModelPath, FileMode.Create); DataContractJsonSerializer JSONSerializer = new DataContractJsonSerializer(typeof(AnomalyDetectionAPI)); JSONSerializer.WriteObject(fs, Instance); fs.Dispose(); return(new AnomalyDetectionResponse(0, "OK")); } catch (Exception Ex) { return(new AnomalyDetectionResponse(400, "Function <Save -JSON- (AnomalyDetecionAPI)>: Unhandled exception:\t" + Ex.ToString())); } }
public void ContinuousTrainData2() { int cnt = 0; double[][] initialCentroids = new double[4][]; initialCentroids[0] = new double[] { 40.0, 10.0 }; initialCentroids[1] = new double[] { 20.0, 10.0 }; initialCentroids[2] = new double[] { 40.0, 20.0 }; initialCentroids[3] = new double[] { 20.0, 20.0 }; string[] attributes = new string[] { "x", "y" }; int numAttributes = attributes.Length; // 2 in this demo (x,y) int numClusters = 4; int maxCount = 300; SaveLoadSettings sett; var resp = SaveLoadSettings.JSON_Settings(@"C:\Data\Function1.json", out sett, true); AnomalyDetectionAPI kmeanApi = new AnomalyDetectionAPI(null, numClusters, initialCentroids); LearningApi api = new LearningApi(loadMetaData1()); api.UseActionModule <object[][], object[][]>((input, ctx) => { var rawDatalist = getData(cnt); return(rawDatalist); }); //this call must be first in the pipeline api.UseDefaultDataMapper(); api.UseGaussNormalizer(); for (int i = 0; i < 15; i++) { cnt = i; var rawData = api.Run() as double[][]; ClusteringSettings Settings = new ClusteringSettings(rawData, maxCount, numClusters, numAttributes, sett, KmeansAlgorithm: 1, InitialGuess: true, Replace: true); AnomalyDetectionResponse response = kmeanApi.ImportNewDataForClustering(Settings); } }
/// <summary> /// LoadChecks is a function that checks the load settings for errors. Some errors can be corrected. /// </summary> /// <param name="LoadObject">settings to load</param> /// <param name="CheckedLoadObject">the checked settings to load</param> /// <returns>a code and a message that state whether the function succeeded or encountered an error. When the function succeeds, it will return: /// <ul style="list-style-type:none"> /// <li> - Code: 0, "OK" </li> /// </ul> /// </returns> public AnomalyDetectionResponse LoadChecks(SaveLoadSettings LoadObject, out SaveLoadSettings CheckedLoadObject) { if (!File.Exists(LoadObject.ModelPath)) { CheckedLoadObject = null; return(new AnomalyDetectionResponse(200, "Function <LoadChecks -JSON- >: File not found")); } var ADResponse = SaveLoadSettings.JSON_Settings(LoadObject.ModelPath, out CheckedLoadObject, LoadObject.Replace); if (ADResponse.Code != 0) { CheckedLoadObject = null; return(ADResponse); } return(new AnomalyDetectionResponse(0, "OK")); }
/// <summary> /// Save is a function that saves the clustering results. /// </summary> /// <param name="SaveObject">settings to save the AnomalyDetectionAPI instance</param> /// <param name="Results">the clustering results object to be saved</param> /// <returns>a code and a message that state whether the function succeeded or encountered an error. When the function succeeds, it will return: /// <ul style="list-style-type:none"> /// <li> - Code: 0, "OK" </li> /// </ul> /// </returns> public AnomalyDetectionResponse Save(SaveLoadSettings SaveObject, ClusteringResults[] Results) { try { //save the clustering results (in a folder called Result in the desired save path) string ResultPath = Path.GetDirectoryName(SaveObject.ModelPath).ToString() + "\\Result\\" + Path.GetFileNameWithoutExtension(SaveObject.ModelPath).ToString() + ".json"; Directory.CreateDirectory(Path.GetDirectoryName(ResultPath)); FileStream fs = new FileStream(ResultPath, FileMode.Create); DataContractJsonSerializer JSONSerializer = new DataContractJsonSerializer(typeof(ClusteringResults[])); JSONSerializer.WriteObject(fs, Results); fs.Dispose(); return(new AnomalyDetectionResponse(0, "OK")); } catch (Exception Ex) { return(new AnomalyDetectionResponse(400, "Function <Save -JSON- (ClusteringResults[])>: Unhandled exception:\t" + Ex.ToString())); } }
public void TestObjestWithCentroid() { double[][] initialCentroids = new double[4][]; initialCentroids[0] = new double[] { 0.2, -4.0 }; initialCentroids[1] = new double[] { 0.2, -6.0 }; initialCentroids[2] = new double[] { 0.4, -4.0 }; initialCentroids[3] = new double[] { 0.4, -6.0 }; string[] attributes = new string[] { "x", "y" }; var data = getRealDataSample(@"C:\Data\Function1.csv"); List <double[]> list = new List <double[]>(); foreach (var n in data) { double[] d = new double[n.Length]; for (int i = 0; i < n.Length; i++) { d[i] = double.Parse(n[i].ToString()); } list.Add(d); } var rawData = list.ToArray(); int numAttributes = attributes.Length; // 2 in this demo (height,weight) int numClusters = 4; // vary this to experiment (must be between 2 and number data tuples) int maxCount = 300; // trial and error SaveLoadSettings sett; var resp = SaveLoadSettings.JSON_Settings(@"C:\Data\Function1.json", out sett, true); AnomalyDetectionAPI kmeanApi = new AnomalyDetectionAPI(rawData, numClusters); ClusteringSettings Settings = new ClusteringSettings(rawData, maxCount, numClusters, numAttributes, sett, KmeansAlgorithm: 1, InitialGuess: true, Replace: true); AnomalyDetectionResponse response = kmeanApi.ImportNewDataForClustering(Settings); }
/// <summary> /// LoadChecks is a function that checks the load settings for errors. Some errors can be corrected. /// </summary> /// <param name="settings">settings to load</param> /// <param name="saveSettings">the checked settings to load</param> /// <returns>a code and a message that state whether the function succeeded or encountered an error. When the function succeeds, it will return: /// <ul style="list-style-type:none"> /// <li> - Code: 0, "OK" </li> /// </ul> /// </returns> public AnomalyDetectionResponse Validate(SaveLoadSettings settings, out SaveLoadSettings saveSettings) { if (!File.Exists(settings.ModelPath)) { saveSettings = null; return(new AnomalyDetectionResponse(200, "Function <LoadChecks -JSON- >: File not found")); } var adResponse = SaveLoadSettings.JsonSettings(settings.ModelPath, out saveSettings, settings.Replace); if (adResponse.Code != 0) { saveSettings = null; return(adResponse); } return(new AnomalyDetectionResponse(0, "OK")); }
/// <summary> /// SaveChecks is a function that checks the saving settings for errors. Some errors can be corrected. /// </summary> /// <param name="saveSettings">settings to save</param> /// <param name="CheckedSaveObject">the checked settings to save</param> /// <returns>a code and a message that state whether the function succeeded or encountered an error. When the function succeeds, it will return: /// <ul style="list-style-type:none"> /// <li> - Code: 0, "OK" </li> /// </ul> /// </returns> public AnomalyDetectionResponse validateSaveConditions(SaveLoadSettings saveSettings, out SaveLoadSettings CheckedSaveObject) { //if (File.Exists(saveSettings.ModelPath)) //{ // if ((!saveSettings.Replace)) // { // CheckedSaveObject = null; // return new AnomalyDetectionResponse(201, "Function <SaveChecks -JSON- >: File already exists"); // } //} var ADResponse = SaveLoadSettings.JSON_Settings(saveSettings.ModelPath, out CheckedSaveObject, saveSettings.Replace); if (ADResponse.Code != 0) { CheckedSaveObject = null; return(ADResponse); } return(new AnomalyDetectionResponse(0, "OK")); }
public void TestWithNormalize_GaussAndCentroid() { double[][] initialCentroids = new double[4][]; initialCentroids[0] = new double[] { 0.2, -4.0 }; initialCentroids[1] = new double[] { 0.2, -6.0 }; initialCentroids[2] = new double[] { 0.4, -4.0 }; initialCentroids[3] = new double[] { 0.4, -6.0 }; string[] attributes = new string[] { "x", "y" }; // Creates learning api object LearningApi api = new LearningApi(loadMetaData1()); //Real dataset must be defined as object type, because data can be numeric, binary and classification api.UseActionModule <object[][], object[][]>((input, ctx) => { return(getRealDataSample(@"C:\Data\Function15.csv")); }); //this call must be first in the pipeline api.UseDefaultDataMapper(); api.UseGaussNormalizer(); var rawData = api.Run() as double[][]; int numAttributes = attributes.Length; // 2 in this demo (height,weight) int numClusters = 4; // vary this to experiment (must be between 2 and number data tuples) int maxCount = 300; // trial and error SaveLoadSettings sett; var resp = SaveLoadSettings.JSON_Settings(@"C:\Data\Function15.json", out sett, true); AnomalyDetectionAPI kmeanApi = new AnomalyDetectionAPI(rawData, numClusters); ClusteringSettings Settings = new ClusteringSettings(rawData, maxCount, numClusters, numAttributes, sett, KmeansAlgorithm: 1, InitialGuess: true, Replace: true); AnomalyDetectionResponse response = kmeanApi.ImportNewDataForClustering(Settings); }
private void GUIPanel() { GUI.DrawTexture(mainToolbarArea, (Texture)Resources.Load("Fondo2")); GUILayout.BeginArea(mainToolbarArea); GUILayout.Button((Texture)Resources.Load("LogoCompleto"), new GUIStyle(), GUILayout.Width(300), GUILayout.Height(50)); var rec = EditorGUILayout.BeginVertical(); //GUI.Box(rec, GUIContent.none); GUI.color = new Color32(255, 102, 102, 255); GUI.color = Color.white; GUILayout.BeginHorizontal(); GUILayout.Label("Speed", StylePresets.SUBTITLE); _typeOfSpeed = (TypeOfSpeed)EditorGUILayout.EnumPopup(_typeOfSpeed); GUI.color = scriptTarget.implosiveSpeed >= 0 ? Color.green : Color.red; GUILayout.Label(scriptTarget.implosiveSpeed.ToString("F2"), StylePresets.SUBTITLE); GUILayout.EndHorizontal(); switch (_typeOfSpeed) { case TypeOfSpeed.Implosive: if (scriptTarget.implosiveSpeed > 0) { scriptTarget.implosiveSpeed = -1; } scriptTarget.implosiveSpeed = GUILayout.HorizontalSlider(scriptTarget.implosiveSpeed, 0, -100); break; case TypeOfSpeed.Explosive: if (scriptTarget.implosiveSpeed < 0) { scriptTarget.implosiveSpeed = 1; } scriptTarget.implosiveSpeed = GUILayout.HorizontalSlider(scriptTarget.implosiveSpeed, 0, 100); break; case TypeOfSpeed.Both: scriptTarget.implosiveSpeed = GUILayout.HorizontalSlider(scriptTarget.implosiveSpeed, -100, 100); break; } GUI.color = Color.white; GUILayout.Label("Noise Amount", StylePresets.COMMON); scriptTarget.randomNoise = GUILayout.HorizontalSlider(scriptTarget.randomNoise, 0, 30); scriptTarget.active = GUILayout.Toggle(scriptTarget.active, scriptTarget.active ? "Activate" : "Deactivate"); scriptTarget.distanceGradient = GUILayout.Toggle(scriptTarget.distanceGradient, scriptTarget.distanceGradient ? "Activate Distance Gradient" : "Deactivate Distance Gradient"); GUILayout.FlexibleSpace(); float buttonSize = 50; EditorGUILayout.BeginHorizontal(); EditorGUILayout.BeginVertical(); GUILayout.Label("Advanced", StylePresets.COMMON); if (GUILayout.Button((Texture)Resources.Load("settings"), GUILayout.MaxHeight(buttonSize), GUILayout.MaxWidth(buttonSize))) { if (_myAdvancedSettingsWIndow == null) { _myAdvancedSettingsWIndow = new AdvancedSettingsWindow(); } AdvancedSettingsWindow.OpenWindow(this); } EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical(); GUILayout.Label("Aesthetics", StylePresets.COMMON); if (GUILayout.Button((Texture)Resources.Load("Color"), GUILayout.MaxHeight(buttonSize), GUILayout.MaxWidth(buttonSize))) { if (_myColorWindow == null) { _myColorWindow = new ColorSelectorWindow(); } ColorSelectorWindow.OpenWindow(this); } EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical(); GUILayout.Label("Save/Load", StylePresets.COMMON); if (GUILayout.Button((Texture)Resources.Load("Search"), GUILayout.MaxHeight(buttonSize), GUILayout.MaxWidth(buttonSize))) { if (_mySaveLoadWindow == null) { _mySaveLoadWindow = new SaveLoadSettings(); } SaveLoadSettings.OpenWindow(this); } EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); GUI.color = Color.white; GUILayout.EndArea(); }
/// <summary> /// LoadJSON_ClusteringResults is a function that deserializes and loads a ClusteringResults[] object from a JSON file. /// </summary> /// <param name="LoadObject">settings to load the ClusteringResults[] object</param> /// <returns> /// - Item 1: the loaded ClusteringResults[] object <br /> /// - Item 2: a code and a message that state whether the function succeeded or encountered an error. When the function succeeds, it will return: /// <ul style="list-style-type:none"> /// <li> - Code: 0, "OK" </li> /// </ul> /// </returns> public Tuple <ClusteringResults[], AnomalyDetectionResponse> Load_ClusteringResults(SaveLoadSettings LoadObject) { ClusteringResults[] Obj; try { string ResultPath = Path.GetDirectoryName(LoadObject.ModelPath).ToString() + "\\Result\\" + Path.GetFileNameWithoutExtension(LoadObject.ModelPath).ToString() + ".json"; FileStream fs = new FileStream(ResultPath, FileMode.Open); DataContractJsonSerializer JSONSerializer = new DataContractJsonSerializer(typeof(ClusteringResults[])); Obj = (ClusteringResults[])JSONSerializer.ReadObject(fs); fs.Dispose(); if (Obj.Length == 0) { Obj = null; return(Tuple.Create(Obj, new AnomalyDetectionResponse(206, "Function <Load_ClusteringResults -JSON- >: Can't deserialize file"))); } return(Tuple.Create(Obj, new AnomalyDetectionResponse(0, "OK"))); } catch (Exception Ex) { Obj = null; if (Ex is System.IO.FileNotFoundException) { return(Tuple.Create(Obj, new AnomalyDetectionResponse(200, "Function <Load_ClusteringResults -JSON- >: File not found"))); } if (Ex is System.IO.DirectoryNotFoundException) { return(Tuple.Create(Obj, new AnomalyDetectionResponse(204, "Function<Load_ClusteringResults -JSON- >: Directory not found"))); } if (Ex is FileLoadException) { return(Tuple.Create(Obj, new AnomalyDetectionResponse(202, "Function <Load_ClusteringResults -JSON- >: File cannot be loaded"))); } if (Ex is SerializationException) { return(Tuple.Create(Obj, new AnomalyDetectionResponse(203, "Function <Load_ClusteringResults -JSON- >: File content is corrupted"))); } return(Tuple.Create(Obj, new AnomalyDetectionResponse(400, "Function <Load_ClusteringResults -JSON- >: Unhandled exception:\t" + Ex.ToString()))); } }
public void Set_GameSounds() { PlayerDataSettings loadedData = SaveLoadSettings.LoadPlayer(); int music_vol = loadedData.music_vol_selection; int effect_vol = loadedData.effect_vol_selection; if (music_vol == 0) { Game_Sound.volume = 0f; } else if (music_vol == 1) { Game_Sound.volume = 0.05f; } else if (music_vol == 2) { Game_Sound.volume = 0.10f; } else if (music_vol == 3) { Game_Sound.volume = 0.20f; } else if (music_vol == 4) { Game_Sound.volume = 0.30f; } else if (music_vol == 5) { Game_Sound.volume = 0.40f; } if (effect_vol == 0) { Mushroom_Sound.volume = 0f; Grass_Sound.volume = 0f; Break_Sound.volume = 0f; Ouch_Sound.volume = 0f; Blop_Sound.volume = 0f; Hit_Sound.volume = 0f; } else if (effect_vol == 1) { Mushroom_Sound.volume = 0.1f; Grass_Sound.volume = 0.02f; Break_Sound.volume = 0.05f; Ouch_Sound.volume = 0.2f; Blop_Sound.volume = 0.2f; Hit_Sound.volume = 0.2f; } else if (effect_vol == 2) { Mushroom_Sound.volume = 0.2f; Grass_Sound.volume = 0.04f; Break_Sound.volume = 0.1f; Ouch_Sound.volume = 0.4f; Blop_Sound.volume = 0.4f; Hit_Sound.volume = 0.4f; } else if (effect_vol == 3) { Mushroom_Sound.volume = 0.3f; Grass_Sound.volume = 0.06f; Break_Sound.volume = 0.15f; Ouch_Sound.volume = 0.6f; Blop_Sound.volume = 0.6f; Hit_Sound.volume = 0.6f; } else if (effect_vol == 4) { Mushroom_Sound.volume = 0.4f; Grass_Sound.volume = 0.08f; Break_Sound.volume = 0.22f; Ouch_Sound.volume = 0.8f; Blop_Sound.volume = 0.8f; Hit_Sound.volume = 0.8f; } else if (effect_vol == 5) { Mushroom_Sound.volume = 0.5f; Grass_Sound.volume = 0.1f; Break_Sound.volume = 0.3f; Ouch_Sound.volume = 1f; Blop_Sound.volume = 1f; Hit_Sound.volume = 1f; } }
/// <summary> /// LoadJSON_AnomalyDetectionAPI is a function that deserializes and loads an AnomalyDetectionAPI object from a JSON file. /// </summary> /// <param name="LoadObject">settings to load the AnomalyDetectionAPI instance</param> /// <returns> /// - Item 1: the loaded AnomalyDetectionAPI object <br /> /// - Item 2: a code and a message that state whether the function succeeded or encountered an error. When the function succeeds, it will return: /// <ul style="list-style-type:none"> /// <li> - Code: 0, "OK" </li> /// </ul> /// </returns> //check for another way to keep centroid private public Tuple <AnomalyDetectionAPI, AnomalyDetectionResponse> Load_AnomalyDetectionAPI(SaveLoadSettings LoadObject) { AnomalyDetectionAPI Obj; try { FileStream fs = new FileStream(LoadObject.ModelPath, FileMode.Open); DataContractJsonSerializer JSONSerializer = new DataContractJsonSerializer(typeof(AnomalyDetectionAPI)); Obj = (AnomalyDetectionAPI)JSONSerializer.ReadObject(fs); fs.Dispose(); if (Obj.Centroids == null) { Obj = null; return(Tuple.Create(Obj, new AnomalyDetectionResponse(206, "Function <Load_AnomalyDetectionAPI -JSON- >: Can't deserialize file"))); } return(Tuple.Create(Obj, new AnomalyDetectionResponse(0, "OK"))); } catch (Exception Ex) { Obj = null; if (Ex is System.IO.FileNotFoundException) { return(Tuple.Create(Obj, new AnomalyDetectionResponse(200, "Function<Load_AnomalyDetectionAPI -JSON- >: File not found"))); } if (Ex is System.IO.DirectoryNotFoundException) { return(Tuple.Create(Obj, new AnomalyDetectionResponse(204, "Function<Load_AnomalyDetectionAPI -JSON- >: Directory not found"))); } if (Ex is FileLoadException) { return(Tuple.Create(Obj, new AnomalyDetectionResponse(202, "Function<Load_AnomalyDetectionAPI -JSON- >: File cannot be loaded"))); } if (Ex is SerializationException) { return(Tuple.Create(Obj, new AnomalyDetectionResponse(203, "Function<Load_AnomalyDetectionAPI -JSON- >: File content is corrupted"))); } return(Tuple.Create(Obj, new AnomalyDetectionResponse(400, "Function<Load_AnomalyDetectionAPI -JSON- >: Unhandled exception:\t" + Ex.ToString()))); } }