Stats
This commit is contained in:
		
							parent
							
								
									e20fc07053
								
							
						
					
					
						commit
						9bb977dedb
					
				| @ -249,7 +249,6 @@ namespace Matomat | |||||||
|                                    "²²²²²²²²²²²²²²²²²²²²²²²²²²²²" + p[0] + |                                    "²²²²²²²²²²²²²²²²²²²²²²²²²²²²" + p[0] + | ||||||
|                                    "²    MATOMAT Wilkommen!    ²" + p[1] + |                                    "²    MATOMAT Wilkommen!    ²" + p[1] + | ||||||
|                                    "² Frohes genießen der Mate ²" + p[2]); |                                    "² Frohes genießen der Mate ²" + p[2]); | ||||||
|             Factory.getLCD().print("µ_¶·-¸¹ºµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµ"); |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         public static void showUserInfo(User user) |         public static void showUserInfo(User user) | ||||||
| @ -303,6 +302,41 @@ namespace Matomat | |||||||
| 
 | 
 | ||||||
|         public static void InsShowStats(User user, bool lastMonth = true) |         public static void InsShowStats(User user, bool lastMonth = true) | ||||||
|         { |         { | ||||||
|  |             List<Product> products = History.GetDrunkProducts(user, lastMonth); | ||||||
|  |             foreach (Product item in products) | ||||||
|  |             { | ||||||
|  |                 string output=""; | ||||||
|  |                 if (lastMonth) | ||||||
|  |                 { | ||||||
|  |                     output += "   Dein Verbrauch im letzten Monat an   "; | ||||||
|  |                 } | ||||||
|  |                 else | ||||||
|  |                 { | ||||||
|  |                     output += "  Dein Verbrauch seit Anbeginn der Zeit "; | ||||||
|  |                 } | ||||||
|  |                 output += Factory.getLCD().CenterString("\""+item.GetName()+"\""); | ||||||
|  |                 Tuple<int, double> sum = History.GetDrunkProductsSum(user, item, lastMonth); | ||||||
|  |                 output += Factory.getLCD().CenterString(sum.Item1 + " Flaschen mit " + sum.Item2.ToString("N2") + " g Koffein"); | ||||||
|  |                 output += " Verlauf: "; | ||||||
|  |                 List<int> chart = History.GetDrunkProductsChart(user, item, lastMonth); | ||||||
|  |                 foreach (int value in chart) | ||||||
|  |                 { | ||||||
|  |                     switch (value) | ||||||
|  |                     { | ||||||
|  |                         case 0: output += "µ"; break; | ||||||
|  |                         case 1: output += "_"; break; | ||||||
|  |                         case 2: output += "¶"; break; | ||||||
|  |                         case 3: output += "·"; break; | ||||||
|  |                         case 4: output += "-"; break; | ||||||
|  |                         case 5: output += "¸"; break; | ||||||
|  |                         case 6: output += "¹"; break; | ||||||
|  |                         case 7: output += "º"; break; | ||||||
|  |                         default: output += " "; break; | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |                 Factory.getLCD().print(output, 5); | ||||||
|  |                 System.Threading.Thread.Sleep(4500); | ||||||
|  |             } | ||||||
|             /** Alle Daten aus der DB Holen die aus dem zeitraum für den user da sind zu Produkt X |             /** Alle Daten aus der DB Holen die aus dem zeitraum für den user da sind zu Produkt X | ||||||
|              * Lege liste mit 40 plätzen an |              * Lege liste mit 40 plätzen an | ||||||
|              * Teile Zeit auf die 40 Plätze auf, älteste bewegung = t0, neueste bewegung = t40 |              * Teile Zeit auf die 40 Plätze auf, älteste bewegung = t0, neueste bewegung = t40 | ||||||
| @ -311,6 +345,16 @@ namespace Matomat | |||||||
|              * Rechne die prozentuale getränke pro platz |              * Rechne die prozentuale getränke pro platz | ||||||
|              * erstelle en Graphen |              * erstelle en Graphen | ||||||
|              */ |              */ | ||||||
|  | 
 | ||||||
|  |             /*1234567890123456789012345678901234567890 | ||||||
|  |              * Verlauf: -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ | ||||||
|  |              *  Dein Verbrauch seit Anbeginn der Zeit  | ||||||
|  |              *   Dein Verbrauch im letzten Monat an    | ||||||
|  |              *              "Club-Mate" | ||||||
|  |              *   1221 Flaschen mit 101,22 g Koffein | ||||||
|  |              *_-----___--__-_--_----_----_-------___-- | ||||||
|  |              * | ||||||
|  |              */ | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -90,5 +90,117 @@ namespace Matomat.Model | |||||||
|             h.bind(k); |             h.bind(k); | ||||||
|             h.store(); |             h.store(); | ||||||
|         } |         } | ||||||
|  | 
 | ||||||
|  |         public static List<Product> GetDrunkProducts(User u, bool lastMonth) | ||||||
|  |         { | ||||||
|  |             DBQuery query = Factory.getDBO().getQuery(true); | ||||||
|  |             query.select(Factory.getDBO().quoteName("p.barcode", "id")); | ||||||
|  |             query.from(Factory.getDBO().quoteName("history", "h")); | ||||||
|  |             query.leftJoin(Factory.getDBO().quoteName("product", "p") + " ON " + Factory.getDBO().quoteName("p.id") + " = " + Factory.getDBO().quoteName("h.prod")); | ||||||
|  |             query.where(Factory.getDBO().quoteName("h.user") + " = " + Factory.getDBO().quote(u.GetId().ToString())); | ||||||
|  |             if (lastMonth) | ||||||
|  |             { | ||||||
|  |                 query.where(Factory.getDBO().quoteName("h.time") + " >= DATE_SUB(NOW(),INTERVAL 30 DAY)"); | ||||||
|  |             } | ||||||
|  |             query.group(Factory.getDBO().quoteName("h.prod")); | ||||||
|  | 
 | ||||||
|  |             Factory.getDBO().setQuery(query); | ||||||
|  | 
 | ||||||
|  |             List<object[]> rows = Factory.getDBO().getResultList(); | ||||||
|  |             List<Product> ret = new List<Product>(); | ||||||
|  |             if (rows == null) | ||||||
|  |             { | ||||||
|  |                 return ret; | ||||||
|  |             } | ||||||
|  |             foreach (object[] row in rows) | ||||||
|  |             { | ||||||
|  |                 ret.Add(new Product((long)row[0])); | ||||||
|  |             } | ||||||
|  |             return ret; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         public static Tuple<int, double> GetDrunkProductsSum(User u, Product item, bool lastMonth) | ||||||
|  |         { | ||||||
|  |             DBQuery query = Factory.getDBO().getQuery(true); | ||||||
|  |             query.select("COUNT(*) AS " + Factory.getDBO().quoteName("boddles")); | ||||||
|  |             query.select("SUM(" + Factory.getDBO().quoteName("p.caffeine") + ") AS " + Factory.getDBO().quoteName("caffeine")); | ||||||
|  |             query.from(Factory.getDBO().quoteName("history", "h")); | ||||||
|  |             query.leftJoin(Factory.getDBO().quoteName("product", "p") + " ON " + Factory.getDBO().quoteName("p.id") + " = " + Factory.getDBO().quoteName("h.prod")); | ||||||
|  |             query.where(Factory.getDBO().quoteName("h.user") + " = " + Factory.getDBO().quote(u.GetId().ToString())); | ||||||
|  |             if (lastMonth) | ||||||
|  |             { | ||||||
|  |                 query.where(Factory.getDBO().quoteName("h.time") + " >= DATE_SUB(NOW(),INTERVAL 30 DAY)"); | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             Factory.getDBO().setQuery(query); | ||||||
|  | 
 | ||||||
|  |             object[] row = Factory.getDBO().getResult(); | ||||||
|  |             if (row == null) | ||||||
|  |             { | ||||||
|  |                 return new Tuple<int, double>(0,0); | ||||||
|  |             } | ||||||
|  |             return new Tuple<int, double>(int.Parse(row[0].ToString()), double.Parse(row[1].ToString()) / 1000); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         public static List<int> GetDrunkProductsChart(User u, Product item, bool lastMonth, int days = 30) | ||||||
|  |         { | ||||||
|  |             DBQuery query = Factory.getDBO().getQuery(true); | ||||||
|  |             query.select(Factory.getDBO().quoteName("h.prod", "product")); | ||||||
|  |             query.select(Factory.getDBO().quoteName("h.time", "time")); | ||||||
|  |             query.from(Factory.getDBO().quoteName("history", "h")); | ||||||
|  |             query.order(Factory.getDBO().quoteName("h.time")+" ASC"); | ||||||
|  |             query.where(Factory.getDBO().quoteName("h.user") + " = " + Factory.getDBO().quote(u.GetId().ToString())); | ||||||
|  |             if (lastMonth) | ||||||
|  |             { | ||||||
|  |                 query.where(Factory.getDBO().quoteName("h.time") + " >= DATE_SUB(NOW(),INTERVAL 30 DAY)"); | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             Factory.getDBO().setQuery(query); | ||||||
|  | 
 | ||||||
|  |             List<object[]> rows = Factory.getDBO().getResultList(); | ||||||
|  |             List<DateTime> bottles = new List<DateTime>(); | ||||||
|  |             List<int> ret = new List<int>(); | ||||||
|  |             if (rows == null) | ||||||
|  |             { | ||||||
|  |                 return ret; | ||||||
|  |             } | ||||||
|  |             foreach (object[] row in rows) | ||||||
|  |             { | ||||||
|  |                 bottles.Add((DateTime)row[1]); | ||||||
|  |             } | ||||||
|  |             DateTime first = bottles.ElementAt(0); | ||||||
|  |             DateTime last = DateTime.Now; | ||||||
|  |             if (lastMonth) | ||||||
|  |             { | ||||||
|  |                 first = last.Subtract(TimeSpan.FromDays(30)); | ||||||
|  |             } | ||||||
|  |             double step = (last - first).TotalSeconds / days; | ||||||
|  |             int max = 0; | ||||||
|  |             List<int> tmplist = new List<int>(); | ||||||
|  |             for (int i = 0; i < days; i++) | ||||||
|  |             { | ||||||
|  |                 inRange_f = first.AddSeconds(step * i); | ||||||
|  |                 inRange_t = first.AddSeconds((step * (i + 1)) - 1); | ||||||
|  |                 int v = bottles.FindAll(inRange).Count(); | ||||||
|  |                 tmplist.Add(v); | ||||||
|  |                 if (v > max)  | ||||||
|  |                     max = v; | ||||||
|  |             } | ||||||
|  |             foreach (int point in tmplist) | ||||||
|  |             { | ||||||
|  |                 ret.Add((int)Math.Round(7 * ((double)point / (double)max))); | ||||||
|  |             } | ||||||
|  |             return ret; | ||||||
|  |         } | ||||||
|  |         private static DateTime inRange_f = DateTime.Now; | ||||||
|  |         private static DateTime inRange_t = DateTime.Now; | ||||||
|  |         private static bool inRange(DateTime el) | ||||||
|  |         { | ||||||
|  |             if (el >= inRange_f && el < inRange_t) | ||||||
|  |             { | ||||||
|  |                 return true; | ||||||
|  |             }  | ||||||
|  |             return false; | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -165,9 +165,9 @@ namespace Matomat.Output | |||||||
|             this.displayEscCode("UDC1@@@@@@@_"); //[1, 0x81] Strich 1te von unten |             this.displayEscCode("UDC1@@@@@@@_"); //[1, 0x81] Strich 1te von unten | ||||||
|             this.displayEscCode("UDC2@@@@@_@@"); //[2, 0x82] Strich 3te von unten |             this.displayEscCode("UDC2@@@@@_@@"); //[2, 0x82] Strich 3te von unten | ||||||
|             this.displayEscCode("UDC3@@@@_@@@"); //[3, 0x83] Strich 4te von unten |             this.displayEscCode("UDC3@@@@_@@@"); //[3, 0x83] Strich 4te von unten | ||||||
|             this.displayEscCode("UDC4@@_@@@@@"); //[4, 0x84] Strich 3te von unten |             this.displayEscCode("UDC4@@_@@@@@"); //[4, 0x84] Strich 6te von unten | ||||||
|             this.displayEscCode("UDC5@_@@@@@@"); //[5, 0x05] Strich 3te von unten |             this.displayEscCode("UDC5@_@@@@@@"); //[5, 0x05] Strich 7te von unten | ||||||
|             this.displayEscCode("UDC6_@@@@@@@"); //[6, 0x06] Strich 3te von unten |             this.displayEscCode("UDC6_@@@@@@@"); //[6, 0x06] Strich 8te von unten | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         private void displayEscCode(string code) |         private void displayEscCode(string code) | ||||||
| @ -219,6 +219,18 @@ namespace Matomat.Output | |||||||
|                          "²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²", status, time); |                          "²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²", status, time); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |         public string CenterString(string text, int length = 40) | ||||||
|  |         { | ||||||
|  |             if (text.Length > length) | ||||||
|  |                 text = text.Substring(0, length); | ||||||
|  |             double textlength = ((((double)length) - text.Length) / 2); | ||||||
|  | 
 | ||||||
|  |             text = text.PadLeft((int)Math.Floor(textlength) + text.Length, ' '); | ||||||
|  |             text = text.PadRight((int)Math.Ceiling(textlength) + text.Length, ' '); | ||||||
|  | 
 | ||||||
|  |             return text; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Prints a text on the display with the minimum duration of the time and beebcodes when status is not Status.OK |         /// Prints a text on the display with the minimum duration of the time and beebcodes when status is not Status.OK | ||||||
|         /// if the text is >= than 160 Chars it will display a border. |         /// if the text is >= than 160 Chars it will display a border. | ||||||
|  | |||||||
| @ -17,6 +17,7 @@ namespace Matomat | |||||||
| 
 | 
 | ||||||
|         public static void Main(string[] args) |         public static void Main(string[] args) | ||||||
|         { |         { | ||||||
|  |             test(); | ||||||
|             InitMainThread(); |             InitMainThread(); | ||||||
|             Thread t = new Thread(MainThread); |             Thread t = new Thread(MainThread); | ||||||
|             t.Start(); |             t.Start(); | ||||||
| @ -27,6 +28,12 @@ namespace Matomat | |||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |         private static void test() | ||||||
|  |         { | ||||||
|  |             User u = new User(2855543482); | ||||||
|  |             Instruction.InsShowStats(u, true); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         #region MainThread |         #region MainThread | ||||||
|         private static void InitMainThread() |         private static void InitMainThread() | ||||||
|         { |         { | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user