Beispiel #1
0
        public static void Main(string[] args)
        {
            List <string> sets = new List <string>();

            foreach (string s in File.ReadAllLines($"{root}{sl}lsettings.ini"))
            {
                if (!s.StartsWith("#") && s.Length > 4)
                {
                    sets.Add(s.Split('#')[0]);
                }
            }

            foreach (string s in sets)
            {
                if (s == null || s.Length == 0)
                {
                    continue;
                }
                else if (s.StartsWith("[PrintDetail]"))
                {
                    printDetail = Convert.ToBoolean(s.Replace("[PrintDetail]", "").Replace("\t", ""));
                }
                else if (s.StartsWith("[SaveLog]"))
                {
                    saveLog = Convert.ToBoolean(s.Replace("[SaveLog]", "").Replace("\t", ""));
                }
                else if (s.StartsWith("[Warn]"))
                {
                    warn      = Convert.ToDouble(s.Replace("[Warn]", "").Replace("\t", "").Split(' ')[0]);
                    warnColor = _color(s.Replace("[Warn]", "").Replace("\t", "").Split(' ')[1]);
                }
                else if (s.StartsWith("[Crit]"))
                {
                    crit      = Convert.ToDouble(s.Replace("[Crit]", "").Replace("\t", "").Split(' ')[0]);
                    critColor = _color(s.Replace("[Crit]", "").Replace("\t", "").Split(' ')[1]);
                }
                else if (s.StartsWith("[Over]"))
                {
                    over      = Convert.ToDouble(s.Replace("[Over]", "").Replace("\t", "").Split(' ')[0]);
                    overColor = _color(s.Replace("[Over]", "").Replace("\t", "").Split(' ')[1]);
                }
                else if (s.StartsWith("[DefaultColor]"))
                {
                    defaultColor = _color(s.Replace("[DefaultColor]", "").Replace("\t", ""));
                }
                else if (s.StartsWith("[Args]") && args.Length < 3)
                {
                    args = s.Replace("[Args]", "").Replace("\t", "").Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries);
                }
            }

            println("Settings:", ConsoleColor.Green);
            println(string.Join("\n", sets));
            println("\n\n...fetching global keys...", ConsoleColor.DarkRed);

            //parses the arguments
            profile.index   = Convert.ToInt32(args[0]);
            outputLogFile   = args[1];
            usdaroot        = $"{root}{sl}usr{sl}share{sl}DBs{sl}USDAstock{sl}";
            usdaNutKeyLines = File.ReadAllLines($"{usdaroot}_nutKeyPairs.TXT");
            root            = $"{root}{sl}usr{sl}profile{profile.index}{sl}"; //sets to user root

            profData          = File.ReadAllLines($"{root}profile.TXT");
            activeFieldsLines = File.ReadAllLines($"{root}activeFields.TXT");
            foreach (string s in profData)
            {
                if (s.StartsWith("[Name]"))
                {
                    profile.name = s.Replace("[Name]", "");
                }
            }

            //grabs the active nutrients
            foreach (string s in activeFieldsLines)
            {
                if (s.Split('#')[0].Trim() != "")
                {
                    _nutrient n = new _nutrient();
                    n.field = s.Split('#')[0].Trim().Split('|')[0];
                    n.rda   = s.Split('#')[0].Trim().Split('|')[1];
                    nutrients.Add(n);
                }
            }

            foreach (string s in usdaNutKeyLines)
            {
                if (s.Split('|')[1] == "NDBNo")
                {
                    ndbnos = File.ReadAllLines($"{usdaroot}{s.Split('|')[0]}");
                }
                foreach (_nutrient n in nutrients)
                {
                    if (n.field == s.Split('|')[1])
                    {
                        n.fileName = s.Split('|')[0];
                    }
                }
            }
            println("...reading in USDAstock...", ConsoleColor.DarkRed);
            print("\nCurrent user: "******"{rootSpare}{sl}usr{sl}share{sl}_rel_USDAstock"))
                {
                    if (!s.Split(Path.DirectorySeparatorChar)[s.Split(Path.DirectorySeparatorChar).Length - 1].StartsWith("_"))
                    {
                        foreach (string st in File.ReadAllLines($"{s}{sl}_dbInfo.TXT"))
                        {
                            if (st.StartsWith("[Field]"))
                            {
                                fields.Add(st.Replace("[Field]", ""));
                            }
                        }
                    }
                }
                //paired fields (user-specific)
                //TODO: add work here
                //foreach (string s in Directory.GetDi)
            }
            //grabs only active fields
            List <_nutrient> newNutrients = new List <_nutrient>();

            foreach (_nutrient n in nutrients)
            {
                if (fields.Contains(n.field))
                {
                    newNutrients.Add(n);
                }
            }
            nutrients = newNutrients;

            //reads in data from main database
            usdaFileNameLinePairs = new Dictionary <string, string[]>();
            foreach (string s in fields)
            {
                foreach (string st in usdaNutKeyLines)
                {
                    if (st.Split('|')[1] == s)
                    {
                        usdaFileNameLinePairs.Add(st.Split('|')[0], File.ReadAllLines($"{usdaroot}{st.Split('|')[0]}"));
                    }
                }
            }
            println();

            //loops thru dates, reads in the user foodlog and computes results
            for (int i = 2; i < args.Length; i++)
            {
                //prints the results
                try { printLog(args[i], nutrients); }
                catch (Exception e)
                {
                    printE(e);
                    continue;
                }
                foreach (_nutrient n in nutrients)
                {
                    n.consumed = 0;
                }
            }
            if (saveLog)
            {
                Directory.CreateDirectory(Path.GetDirectoryName(outputLogFile));
                File.WriteAllLines(outputLogFile, outputLog);
                Console.Write("Log saved to ");
                println(outputLogFile, ConsoleColor.Cyan);
            }
            println("press any key to exit...");
            Console.ReadKey();
            Console.WriteLine();
        }
Beispiel #2
0
        private static double printp(_nutrient nut)
        {
            double c = 0;
            double r = 1;

            try
            {
                c = nut.consumed;
                r = Convert.ToDouble(nut.rda.Split(' ')[0]);
            }
            catch (Exception e)
            {
                printE(e);
                return(0);
            }
            double       x     = c / r;
            ConsoleColor color = defaultColor;

            if (x > over)
            {
                color = overColor;
            }
            if (x > 1.0)
            {
                x = 1.0;
            }

            else if (x < warn && x > crit)
            {
                color = warnColor;
            }
            else if (x <= crit)
            {
                color = critColor;
            }

            string prog = "==================================================";
            int    eL   = prog.Length;

            eL = Convert.ToInt32(eL * x);
            int spac = prog.Length - eL;

            prog = "<";
            for (int i = 0; i < eL; i++)
            {
                prog += "=";
            }
            for (int i = 0; i < spac; i++)
            {
                prog += " ";
            }
            string pad = "";

            for (int i = 0; i < (20 - $"[{Math.Round(c, 1)}/{nut.rda.Split(' ')[0]} {nut.unit}".Length); i++)
            {
                pad += " ";
            }
            prog += $"> {100 * Math.Round(c / r, 3)}% \t[{Math.Round(c, 1)}/{nut.rda.Split(' ')[0]} {nut.unit}{pad} -- {nut.field}]";
            if (printDetail)
            {
                prog += $" {{{nut.contrib}}}";
            }
            println(prog, color);
            return(x);
        }