[LuisIntent("productionYield")] //Done public async Task productionYield(IDialogContext context, IAwaitable <IMessageActivity> activity, LuisResult result) { bool status = checkAuthority(memberGroup, "IT"); if (status) { List <string> EntityType = new List <string>(); List <string> EntityName = new List <string>(); // check entities int entitiesCount = result.Entities.Count; for (int i = 0; i < entitiesCount; i++) { EntityType.Add(result.Entities[i].Type); EntityName.Add(result.Entities[i].Entity); } if (EntityType.Contains("yield.option")) { string option = EntityName[EntityType.IndexOf("yield.option")].ToLower(); DateTime duration = DateTime.UtcNow; if (EntityType.Contains("builtin.datetimeV2.date")) { var resolutionValue = (IList <object>)result.Entities[0].Resolution["values"]; foreach (var value in resolutionValue) { duration = Convert.ToDateTime(((IDictionary <string, object>)value)["value"]); } } if (option == "good") { status1Object JSON = await getStatus.getStatus1("GoodParts", ""); string response = transformResponse.processTotalAndGoodParts(JSON, duration, "Good parts"); await context.PostAsync(response); } else { status1Object JSON = await getStatus.getStatus1("TotalParts", ""); string response = transformResponse.processTotalAndGoodParts(JSON, duration, "Total parts"); await context.PostAsync(response); } } else { await context.PostAsync("Are you missing something?"); } context.Wait(MessageReceived); } else { await context.PostAsync("Sorry, you are not authorized, please sign in with an authorized account."); context.Wait(MessageReceived); } }
[LuisIntent("operatorTime")] //Done public async Task operatorTime(IDialogContext context, IAwaitable <IMessageActivity> activity, LuisResult result) { bool status = checkAuthority(memberGroup, "IT"); if (status) { List <string> EntityType = new List <string>(); List <string> EntityName = new List <string>(); // check entities int entitiesCount = result.Entities.Count; for (int i = 0; i < entitiesCount; i++) { EntityType.Add(result.Entities[i].Type); EntityName.Add(result.Entities[i].Entity); } if (EntityType.Contains("venue")) { string station = EntityName[EntityType.IndexOf("venue")]; string stationCall = station; DateTime duration = DateTime.UtcNow; //trim station name if (station.Contains("station")) { stationCall = station.Substring(station.Length - 1); } if (EntityType.Contains("builtin.datetimeV2.date")) { var resolutionValue = (IList <object>)result.Entities[0].Resolution["values"]; foreach (var value in resolutionValue) { duration = Convert.ToDateTime(((IDictionary <string, object>)value)["value"]); } } status1Object JSON = await getStatus.getStatus1("workingTime", stationCall); string response = transformResponse.processWorkingTime(JSON, duration, station); await context.PostAsync(response); } else { await context.PostAsync("Are you missing the station?"); } context.Wait(MessageReceived); } else { await context.PostAsync("Sorry, you are not authorized, please sign in with an authorized account."); context.Wait(MessageReceived); } }
public static string processDefect(status1Object JSON, string station) { int count = JSON.value.Count(); List <string> readings = new List <string>(); List <DateTime> dates = new List <DateTime>(); for (int i = 0; i < count; i++) { readings.Add(JSON.value[i].Value); dates.Add(JSON.value[i].Timestamp); } int latest = dates.IndexOf(dates.Max()); return($"Latest defect for {station} is {readings[latest]}."); }
public static string processWorkingTime(status1Object JSON, DateTime duration, string station) { int count = JSON.value.Count(); List <double> readings = new List <double>(); for (int i = 0; i < count; i++) { if (JSON.value[i].Timestamp.AddHours(8).Date.Equals(duration.Date)) { readings.Add(Convert.ToDouble(JSON.value[i].Value)); } } double total = readings.Sum(); return($"Operators are spending {total.ToString()} time at {station}"); }
public static string processTotalAndGoodParts(status1Object JSON, DateTime duration, string indicator) { int count = JSON.value.Count(); List <double> readings = new List <double>(); for (int i = 0; i < count; i++) { if (JSON.value[i].Timestamp.AddHours(8).Date.Equals(duration.Date)) { readings.Add(Convert.ToDouble(JSON.value[i].Value)); } } double total = readings.Sum(); return($"{indicator} for {duration.ToString("dd-MM-yyyy")} is {total.ToString()}"); }
[LuisIntent("defectDetection")] //Done public async Task defectDetection(IDialogContext context, IAwaitable <IMessageActivity> activity, LuisResult result) { bool status = checkAuthority(memberGroup, "IT"); if (status) { List <string> EntityType = new List <string>(); List <string> EntityName = new List <string>(); // check entities int entitiesCount = result.Entities.Count; for (int i = 0; i < entitiesCount; i++) { EntityType.Add(result.Entities[i].Type); EntityName.Add(result.Entities[i].Entity); } if (EntityType.Contains("venue")) { string station = EntityName[EntityType.IndexOf("venue")]; string stationCall = station; //trim station name if (station.Contains("station")) { stationCall = station.Substring(station.Length - 1); } status1Object JSON = await getStatus.getStatus1("LatestDefect", ""); //check string response = transformResponse.processDefect(JSON, station); await context.PostAsync(response); } else { await context.PostAsync("Sorry, are you missing the station?"); } context.Wait(MessageReceived); } else { await context.PostAsync("Sorry, you are not authorized, please sign in with an authorized account."); context.Wait(MessageReceived); } }
public static string processScrapValue(status1Object JSON, string calculation, DateTime duration) { int count = JSON.value.Count(); List <double> readings = new List <double>(); //generate the value needed for (int i = 0; i < count; i++) { if (JSON.value[i].Timestamp.AddHours(8).Date.Equals(duration.Date)) { readings.Add(Convert.ToDouble(JSON.value[i].Value)); } } double total = 0; if (calculation == "total") { total = readings.Sum(); } return($"Total value is {total.ToString()}."); }
public static async Task <status1Object> getStatus1(string indicator, string station) { var http = new HttpClient(); http.DefaultRequestHeaders.Add("Accept", "application/json;odata=nometadata"); string columnSelection = "&$select=Timestamp,Indicator,Station,Value"; string checkFilter = "&$filter=Indicator%20eq%20'" + indicator + "'"; if (station != "") { checkFilter = checkFilter + "%20and%20Station%20eq%20'" + station + "'"; } string requestURL = baseURL1 + tableSig1 + columnSelection + checkFilter; var response = await http.GetAsync(requestURL); var result2 = await response.Content.ReadAsStringAsync(); status1Object JSONObj = JsonConvert.DeserializeObject <status1Object>(result2); return(JSONObj); }