Beispiel #1
0
        public FileResult downloadHandlerCSV(modelDataResult data)
        {
            string path     = (_context.getRaw(data.uniqueID).rawAddress).Replace("LOG", "RUN");
            string filename = path.Split(@"\").Last().Replace("txt", "csv");

            ProcessStartInfo startInfo = new ProcessStartInfo();

            startInfo.CreateNoWindow = true;
            startInfo.FileName       = @"C:\Users\griff\Workspace\TangenBiosciences\Tangen\TangenDataPortal\Portal\Portal\scripts\JSONrawdataconvert.exe";
            startInfo.Arguments      = "-p " + path;

            if (System.IO.File.Exists(path))
            {
                try
                {
                    using (Process exeProcess = Process.Start(startInfo))
                    {
                        exeProcess.WaitForExit();
                        FileStream fs = System.IO.File.OpenRead(path);
                        return(File(fs, "text/plain", filename));
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
            return(null);
        }
Beispiel #2
0
        /* Batch download handler */
        public FileResult batchDownloadHandler(string input)
        {
            byte[] fileBytes = null;

            using (var memoryStream = new MemoryStream())
            {
                using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true))
                {
                    foreach (string idStr in input.Split(","))
                    {
                        int             id     = Convert.ToInt32(idStr);
                        modelDataResult result = _context.returnResultFromID(id);

                        result.targets = _context.returnTargets(id);
                        result.wells   = _context.returnWells(id);

                        string resultsJSON = JsonConvert.SerializeObject(result, Formatting.Indented);
                        var    demoFile    = archive.CreateEntry(result.uniqueID + ".json");

                        using (var entryStream = demoFile.Open())
                            using (var streamWriter = new StreamWriter(entryStream))
                            {
                                streamWriter.Write(resultsJSON);
                            }
                    }
                }

                fileBytes = memoryStream.ToArray();

                Stream memstream = new MemoryStream(fileBytes);
                return(File(memstream, "application/zip", System.DateTime.Now + ".zip"));
            }
        }
Beispiel #3
0
        /* View results JSON handler */
        public JsonResult viewResults(modelDataResult data)
        {
            data.targets = _context.returnTargets(data.ID);
            data.wells   = _context.returnWells(data.ID);

            string resultsJSON = JsonConvert.SerializeObject(data, Formatting.Indented);

            return(Json(JObject.Parse(resultsJSON)));
        }
Beispiel #4
0
        /* ========================================= */
        /*             DOWNLOAD HANDLERS             */
        /* ========================================= */

        /* Results JSON download handler */
        public IActionResult downloadHandlerResult(modelDataResult data)
        {
            data.targets = _context.returnTargets(data.ID);
            data.wells   = _context.returnWells(data.ID);

            string resultsJSON = JsonConvert.SerializeObject(data, Formatting.Indented);
            Stream memstream   = new MemoryStream(Encoding.ASCII.GetBytes(resultsJSON));

            return(File(memstream, "application/json", data.instrumentName + "-" + data.sampleID + "-" + System.DateTime.Now.ToString() + ".json"));
        }
Beispiel #5
0
        /* Generate graph */
        public modelGraph generateGraph(modelDataResult result)
        {
            modelGraph graph = new modelGraph();

            int    itx        = 0;
            string path       = _context.returnResultFromID(result.ID).rawAddress;
            int    fileLength = System.IO.File.ReadLines(path).ToArray().Length;

            foreach (string line in System.IO.File.ReadLines(path))
            {
                if ((itx > 4 && itx < fileLength - 3) && (!line.Equals("")))
                {
                    var splitLine = line.Split(",");

                    for (int i = 0; i <= splitLine.Length - 1; i++)
                    {
                        if (splitLine[i] == null || splitLine[i].Equals(" "))
                        {
                            splitLine[i] = "0";
                        }
                    }

                    graph.axisX        += String.Format(splitLine[0] + ",");
                    graph.plate        += String.Format(splitLine[1] + ",");
                    graph.tube         += String.Format(splitLine[2] + ",");
                    graph.diskTop      += String.Format(splitLine[3] + ",");
                    graph.diskBottom   += String.Format(splitLine[4] + ",");
                    graph.fluidTemp    += String.Format(splitLine[5] + ",");
                    graph.piezoCurrent += String.Format(splitLine[6] + ",");
                    //graph.ledCurrent += String.Format(splitLine[7] + ",");
                }

                else if (itx == fileLength - 3)
                {
                    break;
                }

                itx++;
            }

            return(graph);
        }
Beispiel #6
0
        /* Raw data download handler */
        public FileResult downloadHandlerRaw(modelDataResult data)
        {
            string path     = (_context.getRaw(data.uniqueID).rawAddress).Replace("LOG", "RUN");
            string filename = path.Split(@"\").Last();

            if (System.IO.File.Exists(path))
            {
                try
                {
                    FileStream fs = System.IO.File.OpenRead(path);
                    return(File(fs, "text/plain", filename));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }

            return(null);
        }
Beispiel #7
0
        /* Generate report */
        public IActionResult Report(modelDataResult result)
        {
            modelTarget[]     targets   = _context.returnTargets(result.ID);
            modelWell[]       wells     = _context.returnWells(result.ID);
            List <modelStats> statsList = new List <modelStats>();
            string            cq        = "";
            string            wellno    = "";

            foreach (modelTarget target in targets)
            {
                modelStats model = new modelStats()
                {
                    species = target.Name,
                    result  = Convert.ToInt32(target.Outcome)
                };

                statsList.Add(model);
            }

            int idx = 1;

            foreach (modelWell well in wells)
            {
                cq     += (well.Cq + ",");
                wellno += (idx + ",");

                idx++;
            }

            modelPackage pckg = new modelPackage()
            {
                singularResult = _context.returnResultFromID(result.ID),
                graph          = generateGraph(result),
                cqList         = cq,
                wellnoList     = wellno,
                stats          = statsList.ToArray()
            };

            return(View(pckg));
        }
Beispiel #8
0
        public void forcefeed(int amount)
        {
            HttpContext.Session.SetInt32("DEV_totalamount", amount);
            HttpContext.Session.SetInt32("DEV_currentamount", 1);
            HttpContext.Session.SetString("DEV_timestarted", DateTime.Now.ToString());
            HttpContext.Session.SetString("DEV_timeended", "...");

            Random random = new Random();

            for (int i = 1; i <= amount; i++)
            {
                modelDataResult data = new modelDataResult()
                {
                    uniqueID         = random.Next(0, 999999).ToString(),
                    downloadDateTime = Convert.ToString(System.DateTime.Now)
                };

                _context.addEntry(data);
                HttpContext.Session.SetInt32("DEV_currentamount", i);
            }

            HttpContext.Session.SetString("DEV_timeended", DateTime.Now.ToString());
            //HttpContext.Session.SetInt32("DEV_currentamount", 0);
        }
Beispiel #9
0
        /* Migrate */
        public void batchMerge(string baseDirectory)
        {
            //These SIGNALR warnings are okay

            HttpContext.Session.SetInt32("progress", 1);

            sendLog("...");
            sendLog("Starting batch merge...");

            double total = 0;
            double idx   = 0;

            Array.ForEach(Directory.GetDirectories(baseDirectory), x => total += Directory.GetFiles(x).Where(file => file.Split(@"\").Last().Split("_")[0].Equals("LOG")).ToArray().Length);


            foreach (String dir in Directory.GetDirectories(baseDirectory))
            {
                string   dateString = dir.Split(@"\").Last();
                DateTime date       = DateTime.ParseExact(dir.Split("\\").Last(), "MMddyy", CultureInfo.InvariantCulture);
                string   path       = (@"C:\Users\griff\Documents\TangenDataStore\" + dateString);


                //Create date directory (ex: 021118)
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                    sendLog("New directory '" + dir.Split("\\").Last() + "' created");
                }

                foreach (String file in Directory.GetFiles(dir))
                {
                    string fileName = file.Split(@"\").Last();
                    //Check if its a log file
                    if (fileName.Contains("LOG"))
                    {
                        foreach (String subfile in Directory.GetFiles(dir))
                        {
                            //For every log file check for a corresponding run file
                            HttpContext.Session.SetInt32("progress", (HttpContext.Session.GetInt32("progress") ?? 1) + 1);

                            if (subfile.Contains("RUN"))
                            {
                                string x = subfile.Split(@"\").Last().Replace("RUN", "LOG");
                                if (x.Equals(fileName))
                                {
                                    //Set new paths
                                    string newName = convertFileName(file.Split(@"\").Last());
                                    string newPath = path + @"\LOG_" + newName + ".txt";

                                    string newNameRUN = convertFileName(subfile.Split(@"\").Last());
                                    string newPathRUN = path + @"\RUN_" + newName + ".txt";

                                    //If the run file is found then copy the log file to serverside storage
                                    try
                                    {
                                        System.IO.File.Copy(file, newPath);
                                        System.IO.File.Copy(subfile, newPathRUN);
                                    }
                                    catch (Exception ex)
                                    {
                                        sendLog("cant write file");
                                    }

                                    //Adding data to database for runs and tracker tables
                                    modelDataResult data = new modelDataResult()
                                    {
                                        uniqueID         = newName,
                                        rawAddress       = newPath,
                                        downloadDateTime = date.ToString()
                                    };

                                    modelTracker tracker = new modelTracker()
                                    {
                                        dateTime = date.ToString(),
                                        uniqueID = newName
                                    };

                                    _context.addEntry(tracker);
                                    _context.addEntry(data);

                                    //sendLog("Merged file '" + subfile + "' \u001b[32msuccessfully\u001b[0m");
                                    idx++;
                                    updateProgressBar((idx / total) * 100);
                                }
                            }
                        }
                    }
                }
            }

            sendLog("\u001b[32mMerge completed successfully!\u001b[0m");
        }
Beispiel #10
0
        /* ========================================= */
        /*     DATA MANIPULATION / LOGIC HANDLERS    */
        /* ========================================= */

        /* Show graph */
        public IActionResult showGraph(modelDataResult result)
        {
            return(View(generateGraph(result)));
        }