// Use this for initialization void Awake() { NPC_Talk = GameObject.Find("talkmanager").GetComponent <NPCcontroller_test>(); // NPC_Talk = FindObjectOfType<DialogueHolder_NPC>(); canvas = GameObject.Find("Canvas"); option_0 = canvas.transform.Find("option").gameObject; Image = option_0.transform.GetChild(0).gameObject; S_0 = option_0.transform.GetChild(1).gameObject; S_1 = option_0.transform.GetChild(2).gameObject; test_s0 = S_0.GetComponent <Text>(); test_s1 = S_1.GetComponent <Text>(); if (option_0 != null) { option_0.SetActive(false); } else { Debug.Log("F**k!"); } test_color_volume = 0; }
public static void Run() { int i = 0; int check = 0; while (i < 100) { DateTime now_ = DateTime.Now; TimeSpan time = new TimeSpan(now_.Ticks); double running_Remainder = (double)time.TotalSeconds % 60; if (running_Remainder < 15) { check++; if (check == 1) { Clear_Console(console_top); Console.SetCursorPosition(0, console_top); Set_Remaining_Minutes(DateTime.Now); //Set value of minutes remaining until next interval double latest_demand = 0; try { BECDemand.LoadBECData(); //load demand to BECDemand.Demandstorage latest_demand = BECDemand.Demandstorage.Last(); if ((now_ - BECDemand.BEC_Demand_latest_Date).Minutes < 15) //Check if Demand was updated recently { Set_Defended_Peak_to_Demand(BECDemand.BEC_Demand_latest_Date, latest_demand); } Add_to_Demand_History(latest_demand, BECDemand.BEC_Demand_latest_Date); //add latest demand value to demand history Console.WriteLine("Peak to defend is set to: " + S_0.ToString("####0.00 kVA")); Console.WriteLine("DateTime = " + BECDemand.BEC_Demand_latest_Date + "\nDemand value = " + latest_demand.ToString("####0.00 kVA")); } catch (Exception es) { Console.WriteLine("Failed to load demand, Error: " + es); } double predicted_Ongoing = ((current_slope * Remaining_minutes) + latest_demand); //predicted peek for next interval based on ongoing ROC double predicted_Average = 0.0; try { Console.WriteLine(Remaining_minutes + " minutes are remaining until next interval"); predicted_Ongoing = ((current_slope * Remaining_minutes) + latest_demand); //predicted peek for next interval based on ongoing ROC predicted_Average = -1; //predicted peek for next interval based on average ROC Console.WriteLine("\nOngoing Rate of change of Demand [kVA per minute] = " + current_slope.ToString("####0.00")); Console.WriteLine("With current Ongoing [kVA per minute], at the end of this " + Demand_interval + " minutes interval, Peak will be " + predicted_Ongoing.ToString("####0.00 kVA")); if (Slope_History.Count > 0) { predicted_Average = ((Slope_History.Average() * Remaining_minutes) + latest_demand); Console.WriteLine("\nAverage Rate of change of Demand [kVA per minute] = " + Slope_History.Average().ToString("####0.00")); Console.WriteLine("With current Average [kVA per minute], at the end of this " + Demand_interval + " minutes interval, Peak will be " + predicted_Average.ToString("####0.00 kVA")); } } catch (Exception es) { Console.WriteLine("Failed to update predicted values, Error: " + es); } DateTime date_now = DateTime.Now; try { if (predicted_Average >= 0) { InsertDemandLog(date_now, BECDemand.BEC_Demand_latest_Date, S_0, latest_demand, Demand_interval, current_slope, Slope_History.Average(), predicted_Ongoing, predicted_Average); } else { InsertDemandLog(date_now, BECDemand.BEC_Demand_latest_Date, S_0, latest_demand, Demand_interval, current_slope, predicted_Ongoing); } } catch (Exception es) { Console.WriteLine("Failed to write Demand Logs to Database, Error: " + es); } try { SendLogQueries(SystemLogs_DB); } catch (Exception es) { Console.WriteLine("Failed to write error Logs to Database, Error: " + es); } finally { SystemLogs_DB.Clear(); } try { if ((date_now.Minute + LC_mins_before_interval) % Demand_interval == 0 || date_now.Minute == 0) //at the end of interval { count2++; if (count2 == 1) { if ((date_now - BECDemand.BEC_Demand_latest_Date).Minutes < 15) //Check if Demand was updated recently { double average = BECDemand.Demandstorage.Average(); BECDemand.Demandstorage.Clear(); Console.WriteLine("DateTime = " + BECDemand.BEC_Demand_latest_Date + "\nAverage Demand value = " + average.ToString("####0.00")); if (average + Defence_Range >= S_0) { Console.WriteLine("Demand + Defence range = " + average + Defence_Range); Full_Control_ON(average); if (average > S_0) { S_0 = average; } if (first_start) { control_started_at = DateTime.Now; //update control start time control_removed_at = control_started_at.AddMinutes(1); //update control remove time } if (control_removed_at > control_started_at) //if control was removed earlier { control_started_at = DateTime.Now; //update control start time } } else if (average + (Defence_Range * 2) <= S_0) { Console.WriteLine("Demand + Defence range = " + average + Defence_Range); Control_OFF(average); if (first_start) { control_removed_at = DateTime.Now; //update control remove time control_started_at = control_removed_at.AddMinutes(1); //update control start time } if (control_started_at > control_removed_at) { control_removed_at = DateTime.Now; //update control remove time } if ((DateTime.Now - control_removed_at).TotalMinutes > control_timeout_mins) //apply control if it has been disabled for previous "control_timeout_mins" minutes { can_apply_control = true; } } first_start = false; /* * Defended - 50kVA = BEC demand -> apply load * S0, S (BEC demand at the end of interval) * * if S + 50 >= Defended -> apply full load control * if S + 100 <= Defended -> remove control */ } else { Console.WriteLine(date_now + ". BEC demand is not being updated. Please check server collecting data for BEC"); SystemLogs_DB.Add(date_now + ". BEC demand is not being updated. Please check server collecting data for BEC"); } Slope_History.Clear(); Clear_Demand_History(); } } else { count2 = 0; } } catch (Exception es) { Console.WriteLine("Failed to update Control status, Error: " + es); } Console.WriteLine("Control was started at : " + control_started_at); Console.WriteLine("Control was removed at : " + control_removed_at); if (full_Control_ON) { Console.WriteLine(DateTime.Now + ": Full Control is ON."); } else if (control_OFF) { Console.WriteLine(DateTime.Now + ": Control is OFF."); } } } else { check = 0; } Thread.Sleep(1000); i = 1; } }
// Update is called once per frame void Update() { if (option_0.activeInHierarchy == true) { fadein(); } else { test_color_volume = 0; test_s0.color = new Color(test_s0.color.r, test_s0.color.g, test_s0.color.b, 0); test_s1.color = new Color(test_s1.color.r, test_s1.color.g, test_s1.color.b, 0); } if (NPC_Talk.txt != null) { // Debug.Log(NPC_Talk.txt); t = NPC_Talk.txt; s = t.Split('|'); if (S_0.activeInHierarchy == true && S_1.activeInHierarchy == true) { S_0.GetComponent <Text>().text = s[1]; S_1.GetComponent <Text>().text = s[3]; } // Debug.Log("ttttt"); } if (option_0.activeInHierarchy == true) { if (Input.GetKeyDown(KeyCode.DownArrow)) { if (index < 1) { index++; Vector2 position = S_1.GetComponent <RectTransform>().anchoredPosition; Image.GetComponent <RectTransform>().anchoredPosition = position; } } if (Input.GetKeyDown(KeyCode.UpArrow)) { if (index > 0) { index--; Vector2 position = S_0.GetComponent <RectTransform>().anchoredPosition; Image.GetComponent <RectTransform>().anchoredPosition = position; } } } if (Input.GetKeyDown(KeyCode.Z)) { if (option_0.activeInHierarchy == true) { if (index == 0) { // whereSpawn.story_n++; whereSpawn.story[whereSpawn.story_n] = true; /*s[1] = ""; * s[3] = ""; * s[4] = ""; */ } else if (index == 1) { whereSpawn.story[whereSpawn.story_n] = false; } } } }