Пример #1
0
        public static bool writeBatteryLog(List <BatteryLogEvent> logColl)
        {
            try
            {
                StreamWriter sw = new StreamWriter(path);

                foreach (var log in logColl)
                {
                    String line = "Drained: " + log.getDrainedBatteryPercent().ToString() + "% Elapsed Time: " + log.getElapsedTime();
                    sw.WriteLine(line);
                }
                sw.WriteLine(""); //Empty line

                int             totalDrainage = logColl.Count;
                BatteryLogEvent lastLog       = logColl.ElementAt(logColl.Count - 1);

                sw.WriteLine("Drained " + totalDrainage.ToString() + "% in " + lastLog.getElapsedTime());
                sw.WriteLine("On average, you have used your computer " + AverageDrainage(totalDrainage, lastLog) + " minutes for 1% of your battery.");
                sw.Close();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Пример #2
0
        private static double AverageDrainage(int drainage, BatteryLogEvent lastLog)
        {
            String[] time           = lastLog.getElapsedTime().Split(':');
            int      elapsedMinutes = Int32.Parse(time[0]) * 60 + Int32.Parse(time[1]);

            return(Convert.ToDouble(elapsedMinutes) / drainage);
        }
Пример #3
0
        /*
         * -Counts elapsed usage time
         * -Performs various tasks according to spent time
         */
        private void timer1_Tick(object sender, EventArgs e)
        {
            elapsedSeconds++;
            if (elapsedSeconds > 59)
            {
                elapsedMinutes++;
                elapsedSeconds = 0;

                float currentBattery = getBatteryPercentage();

                if (currentBattery + (this.batteryLogInterval * this.cycleOfTens) <= startingBatteryPercentage)
                {
                    BatteryLogEvent blg = new BatteryLogEvent(this.getElapsedTime(), this.batteryLogInterval);
                    cycleOfTens++;
                    this.logCollector.Add(blg);
                }
            }
            if (elapsedMinutes > 59)
            {
                elapsedHours++;
                elapsedMinutes = 0;
            }
            lblTime.Text = "Elapsed Time: " + elapsedHours + ":" + elapsedMinutes + ":" + elapsedSeconds;
        }