public JsonResult AddToRecipe(List <string> checkedIds, string operation, List <string> comment, List <string> code) { string path = Server.MapPath(@"~/Content/Projects/AutoPrepGrid.json"); string json = System.IO.File.ReadAllText(path); List <Grid> data = JsonConvert.DeserializeObject <List <Grid> >(json); Grid grid = new Grid(); List <string> tables = new List <string>(); List <string> columns = new List <string>(); Dictionary <string, List <string> > Mapping = new Dictionary <string, List <string> >(); try { if (checkedIds != null) { foreach (var item in checkedIds) { if (item.Contains(".")) { tables.Add(item.ToString().Split('.')[0]); } else { tables.Add(item.ToString()); } } if (tables != null) { foreach (var tbl in tables.Distinct()) { var cols = checkedIds.Where(x => x.Contains('.') && x.Contains(tbl)).Select(x => x.ToString().Split('.')[1]).ToList(); Mapping.Add(tbl, cols); columns.AddRange(cols); } } } grid.Operation = operation; grid.Columns = columns; grid.Mapping = Mapping; grid.Tables = tables.Distinct().ToList <string>(); grid.ParentSNo = 0; grid.CodeCell = code; grid.CommentCell = comment; if (data != null) { grid.SNo = data.Count + 1; data.Add(grid); } else { grid.SNo = 1; data = new List <Grid>(); data.Add(grid); } var output = JsonConvert.SerializeObject(data); System.IO.File.WriteAllText(path, output); if (System.IO.File.Exists(@"G:\AutoML-Prep\AutoPrepareMLNotebook.ipynb")) { string ipython = System.IO.File.ReadAllText(@"G:\AutoML-Prep\AutoPrepareMLNotebook.ipynb"); dynamic template = JsonConvert.DeserializeObject <dynamic>(ipython); Metadata newmeta = new Metadata(); int cellcount; List <dynamic> cellslist = new List <dynamic>(); if (template.ToString().Contains("worksheets")) { cellslist = template.worksheets[0].cells.ToObject <List <dynamic> >(); cellcount = template.worksheets[0].cells.Count; } else { cellslist = template.cells.ToObject <List <dynamic> >(); cellcount = template.cells.Count; } Cell cell1 = FormCell(comment); cell1.cell_type = "markdown"; Cell cell2 = FormCell(code); cell2.cell_type = "code"; var commcell = JObject.Parse(JsonConvert.SerializeObject(cell1)); var newcell = JObject.Parse(JsonConvert.SerializeObject(cell2)); cellslist.Insert(cellcount, commcell); cellslist.Insert(cellcount + 1, newcell); var tempcells = JArray.Parse(JsonConvert.SerializeObject(cellslist)); template.cells = tempcells; string outnote = JsonConvert.SerializeObject(template); //string filename = @"AutoPrepareMLNotebook.ipynb"; System.IO.File.WriteAllText(@"G:\AutoML-Prep\AutoPrepareMLNotebook.ipynb", outnote); } else { Notebook note = new Notebook(); List <Cell> cells = new List <Cell>(); Metadata2 newmeta = new Metadata2(); List <string> input = new List <string>() { "<span style='color:blue;font-weight:bold;font-size:20px'> This is an AutoGenerated Notebook from Data Model</span>" }; Cell cell1 = FormCell(input); cell1.cell_type = "markdown"; cells.Add(cell1); List <string> init = new List <string>() { "!pip install --user --no-warn-script-location azureml.dataprep", "!pip install --user pyspark", "import azureml.dataprep as dprep" }; Cell initcell = FormCell(init); initcell.cell_type = "code"; cells.Add(initcell); var comm = FormCell(comment); comm.cell_type = "markdown"; cells.Add(comm); Cell codecell = FormCell(code); codecell.cell_type = "code"; cells.Add(codecell); Kernelspec kernel = new Kernelspec(); kernel.display_name = "Python 3"; kernel.language = "python"; kernel.name = "python3"; CodemirrorMode codemirror = new CodemirrorMode(); LanguageInfo lang = new LanguageInfo(); codemirror.name = "ipython"; codemirror.version = 3; lang.codemirror_mode = codemirror; lang.file_extension = ".py"; lang.mimetype = "text/x-python"; lang.name = "python"; lang.nbconvert_exporter = "python"; lang.pygments_lexer = "ipython3"; lang.version = "3.7.3"; newmeta.language_info = lang; newmeta.kernelspec = kernel; note.metadata = newmeta; note.cells = cells; note.nbformat = 4; note.nbformat_minor = 1; string outnote = JsonConvert.SerializeObject(note); //string filename = @"AutoPrepareMLNotebook.ipynb"; System.IO.File.WriteAllText(@"G:\AutoML-Prep\AutoPrepareMLNotebook.ipynb", outnote); } return(Json(data, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(false, JsonRequestBehavior.AllowGet)); } }
public FlightSafetyReportModelSp getflightSafetyJson(FlightSafetyReportModel sd) { FlightSafetyReportModelSp sddp = new FlightSafetyReportModelSp(); sddp.MobileEntry = true; List <string> strData = sd.ApproachType != null?sd.ApproachType.Trim(',').Split(',').ToList() : null; List <string> relativeStr = sd.Relativeposition != null?sd.Relativeposition.Trim(',').Split(',').ToList() : null; List <string> deviation = sd.ReasonforDeviation != null?sd.ReasonforDeviation.Trim(',').Split(',').ToList() : null; if (strData != null) { ApproachType sfapp = new ApproachType(); sfapp.results = strData; Metadata1 md1 = new Metadata1(); md1.type = "Collection(Edm.String)"; sfapp.__metadata = md1; sddp.ApproachType = sfapp; } if (relativeStr != null) { ReasonForDeviation rsDev = new ReasonForDeviation(); rsDev.results = deviation; Metadata2 md2 = new Metadata2(); md2.type = "Collection(Edm.String)"; rsDev.__metadata = md2; sddp.ReasonforDeviation = rsDev; } if (deviation != null) { IntruderACRelativePosition intru = new IntruderACRelativePosition(); intru.results = deviation; Metadata3 md3 = new Metadata3(); md3.type = "Collection(Edm.String)"; intru.__metadata = md3; sddp.Relativeposition = intru; } sddp.ReportType = "Flight Safety Report";// sd.ReportType; sddp.AircraftRegis = sd.AircraftRegistration; sddp.EventTitle = sd.EventTitle; sddp.FlightNumber = sd.FlightNumber; sddp.DateOfEvent = sd.DateOfEvent.ToString("yyyy-MM-dd") + "T07:00:00Z"; sddp.DepartureStation = sd.DepartureStation; sddp.ArrivalStation = sd.ArrivalStation; sddp.DivertStation = sd.DivertStation; sddp.Area_FIR = sd.Area_FIR; sddp.DescribeEvent = sd.DescribeEvent != null ? "<div class=\"ExternalClass733EA004DCC641EFAFED516F5D12CCA7\"><br>\u200b" + sd.DescribeEvent + "<br><\u002fdiv>" : null; sddp.Attachment = sd.Attachment; sddp.MOR = SSIRShortForm.MORTypeID != null?Convert.ToString(SSIRShortForm.MORTypeID + 1) : null; //Convert.ToString(sd.MOR + 1); sddp.ConfiReport = sd.ConfiReport == true ? "1" : "0"; sddp.ssQ = sd.ssQ == true ? "1" : "0"; sddp.pax = sd.pax; sddp.CommanderPForPM = FlightSafetyReportView.CommanderPForPMpickerValue; if (FlightSafetyReportView.PeoplePickerCommander != null) { sddp.CommandersEmail = FlightSafetyReportView.PeoplePickerCommander.Id.ToString(); } if (FlightSafetyReportView.PeoplePickercrew1email != null) { sddp.FlightCrew1 = FlightSafetyReportView.PeoplePickercrew1email.Id.ToString(); } if (FlightSafetyReportView.PeoplePickercrew2email != null) { sddp.FlightCrew2 = FlightSafetyReportView.PeoplePickercrew2email.Id.ToString(); } sddp.FlightCrew1PFPMOBs = FlightSafetyReportView.FlightCrew1PFPMOBspickerValue; sddp.FlightCrew2PFPMOBs = FlightSafetyReportView.FlightCrew2PFPMOBspickerValue; sddp.Ifflighteventselectphase = FlightSafetyReportView.IfflighteventselectphasepickerValue; sddp.Ifongroundselectwhere = FlightSafetyReportView.IfongroundselectwherepickerValue; sddp.Altitude = sd.Altitude; sddp.IASMach = sd.IASMach; sddp.AutopilotOn = sd.AutopilotOn == true ? "1" : "0"; sddp.ATOn = sd.ATOn == true ? "1" : "0"; // sddp.ApproachType = "{\"__metadata\":{\"type\":\"Collection(Edm.String)\"},\"results\":\"" + apptypestr + "\"}"; sddp.Heading = sd.Heading; sddp.VS = sd.VS; sddp.Gear = FlightSafetyReportView.GearpickerValue; sddp.Speedbrake = FlightSafetyReportView.SpeedbrakepickerValue; sddp.FlapPosition = sd.FlapPosition; sddp.Weight = sd.Weight; sddp.FuelDumping = sd.FuelDumping == true ? "1" : "0"; sddp.SeatbeltSign = sd.SeatbeltSign == true ? "1" : "0"; sddp.MeteorologicalReport = FlightSafetyReportView.MeteorologicalReportpickerValue; sddp.Wind = sd.Wind; sddp.VisRVR = sd.VisRVR; sddp.Temp = sd.Temp; sddp.Light = FlightSafetyReportView.LightpickerValue; sddp.Weather = FlightSafetyReportView.WeatherpickerValue; sddp.Precipitation = FlightSafetyReportView.PrecipitationpickerValue; sddp.Turbulence = FlightSafetyReportView.TurbulencepickerValue; sddp.RWYDirection = sd.RWYDirection; sddp.Conditions = FlightSafetyReportView.ConditionspickerValue; sddp.NAVAIDS = FlightSafetyReportView.NAVAIDSpickerValue; sddp.ClearedAltitude = sd.ClearedAltitude; sddp.DeviationHorizontal = sd.DeviationHorizontal; sddp.Vertical = sd.Vertical; // sddp.ReasonforDeviation = sd.ReasonforDeviation != null ? "<div class=\"ExternalClass733EA004DCC641EFAFED516F5D12CCA7\"><br>\u200b" + sd.ReasonforDeviation + "<br><\u002fdiv>" : null; sddp.TAAlert = sd.TAAlert == true ? "1" : "0"; sddp.RAAlert = sd.RAAlert == true ? "1" : "0"; sddp.RACommand = sd.RACommand; sddp.IntruderACType = sd.IntruderACType; sddp.Callsign = sd.Callsign; // sddp.Relativeposition = sd.Relativeposition != null ? "<div class=\"ExternalClass733EA004DCC641EFAFED516F5D12CCA7\"><br>\u200b" + sd.Relativeposition + "<br><\u002fdiv>" : null; sddp.Bearing = sd.Bearing; sddp.Range = sd.Range; sddp.ATC = FlightSafetyReportView.ATCorAirportReportFiledpickerValue; sddp.ATCUnit = sd.ATCUnit; sddp.Frequency = sd.Frequency; sddp.TypeofWarnings = sd.TypeofWarnings != null ? "<div class=\"ExternalClass733EA004DCC641EFAFED516F5D12CCA7\"><br>\u200b" + sd.TypeofWarnings + "<br><\u002fdiv>" : null; sddp.WildlifeType = sd.WildlifeType; sddp.Numberofbirds = FlightSafetyReportView.NumberofbirdspickerValue; sddp.SizeofWildlife = FlightSafetyReportView.SizeofWildlifepickerValue; sddp.AircraftDamage = FlightSafetyReportView.AircraftDamagepickerValue; sddp.ImpactAreaDamage = sd.ImpactAreaDamage != null ? "<div class=\"ExternalClass733EA004DCC641EFAFED516F5D12CCA7\"><br>\u200b" + sd.ImpactAreaDamage + "<br><\u002fdiv>" : null; sddp.SubmitterEmail = sd.SubmitterEmail; sddp.NameStaffNumber = sd.NameStaffNumber; return(sddp); }