Beispiel #1
0
 public async Task<IEnumerable<BrewTempLog>> Get50Latest()
 {
     using (var db = new BrewMaticContext())
     {
         return await db.TempLogs.OrderByDescending(x => x.Id).Take(50).ToListAsync();
     }
 }
Beispiel #2
0
 public async Task<BrewTempLog> GetLatest()
 {
     using (var db = new BrewMaticContext())
     {
         return await db.TempLogs.OrderByDescending(x => x.Id).FirstAsync();
     }
 }
Beispiel #3
0
 public async Task<int> GetLatestBrew()
 {
     using (var db = new BrewMaticContext())
     {
         return await db.BrewLogs.OrderByDescending(x => x.Id).Select(x => x.Id).FirstOrDefaultAsync();
     }
 }
Beispiel #4
0
        public async Task<BrewMaticNewSettings> Post([FromBody]BrewMaticStatus value)
        {
            _logger.LogDebug($"{DateTime.Now}: Temp1: {value.Temp1}. Temp2: {value.Temp2}. Heater1: {value.Heater1Percentage}%. Heater2: {value.Heater2Percentage}%");

            BrewTargetTemperature t;

            using (var db = new BrewMaticContext())
            {
                var repo = new BrewLogRepository(db);
                t = repo.GetTargetTemp();
                db.TempLogs.Add(new BrewTempLog { Temp1 = value.Temp1, Temp2 = value.Temp2, Heater1Percentage = value.Heater1Percentage, Heater2Percentage = value.Heater2Percentage, TimeStamp = DateTime.Now });
                var count = await db.SaveChangesAsync();
                _logger.LogDebug("{0} records saved to database", count);
            }

            return new BrewMaticNewSettings
            {
                TargetTemp1 = t.Target1,
                TargetTemp2 = t.Target2,
                ScreenContent = new[]
                {
                    "Hello! " + DateTime.UtcNow.AddHours(2).ToString("HH:mm:ss"),
                    "",
                    GetLineString("1", value.Temp1, t.Target1, value.Heater1Percentage),
                    GetLineString("2", value.Temp2, t.Target2, value.Heater2Percentage)
                }
            };
        }
Beispiel #5
0
 public async Task<IEnumerable<DataCaptureValueDto>> GetDefinedDataCaptureValues(int brewId)
 {
     using (var db = new BrewMaticContext())
     {
         var repo = new BrewLogRepository(db);
         return await repo.GetDefinedDataCaptureValues(brewId);
     }
 }
Beispiel #6
0
 public IEnumerable<BrewLogsDto> Get()
 {
     using (var db = new BrewMaticContext())
     {
         var repo = new BrewLogRepository(db);
         return repo.ListBrewLogs().ToList();
     }
 }
Beispiel #7
0
 public async Task<IEnumerable<BrewLogHistoryDto>> GetBrewHistory(int brewId)
 {
     using (var db = new BrewMaticContext())
     {
         var repo = new BrewLogRepository(db);
         return await repo.GetBrewHistory(brewId);
     }
 }
Beispiel #8
0
 public async Task<CurrentBrewDto> Get(int brewId)
 {
     using (var db = new BrewMaticContext())
     {
         var repo = new BrewLogRepository(db);
         return await repo.GetBrewDto(brewId);
     }
 }
Beispiel #9
0
 public void Save([FromBody]DataCaptureValueDto[] values)
 {
     using (var db = new BrewMaticContext())
     {
         var repo = new BrewLogRepository(db);
         repo.SaveDataCaptureValues(values);
         db.SaveChanges();
     }
 }
Beispiel #10
0
 public void GoToPreviousStep([FromBody]int brewId)
 {
     using (var db = new BrewMaticContext())
     {
         var repo = new BrewLogRepository(db);
         repo.GoBackOneStep(brewId);
         db.SaveChanges();
     }
 }
Beispiel #11
0
 public async void Post([FromBody]BrewTargetTemperature value)
 {
     using (var db = new BrewMaticContext())
     {
         var t = await db.TargetTemp.FirstOrDefaultAsync();
         if (t == null)
         {
             t = new BrewTargetTemperature();
             db.Add(t);
         }
         t.Target1 = value.Target1;
         t.Target2 = value.Target2;
         await db.SaveChangesAsync();
     }
 }
Beispiel #12
0
 public async Task<BrewTargetTemperature> Get()
 {
     //todo! Return async data!!
     var logs = new List<BrewTempLog>();
     using (var db = new BrewMaticContext())
     {
         var t = await db.TargetTemp.FirstOrDefaultAsync();
         if (t != null)
             return t;
         t = new BrewTargetTemperature { Target1 = 20, Target2 = 20 };
         db.Add(t);
         await db.SaveChangesAsync();
         return t;
     }
 }
Beispiel #13
0
 public BrewLogRepository(BrewMaticContext db)
 {
     _db = db;
 }
Beispiel #14
0
        public static void Seed()
        {
            using (var db = new BrewMaticContext())
            {
                db.Database.EnsureCreated();
                if (db.TempLogs.Count() == 0)
                {
                    var newLog = new BrewTempLog
                    {
                        Temp1 = 0,
                        Temp2 = 0,
                        Heater1Percentage = 0,
                        Heater2Percentage = 0,
                        TimeStamp = DateTime.Now
                    };
                    db.TempLogs.Add(newLog);

                    var initialStep = new BrewStepTemplate
                    {
                        Name = "Initial",
                        CompleteButtonText = "Start Warmup",
                        Instructions = "Get ready for brewing"
                    };
                    db.Add(initialStep);
                    db.Add(new BrewStepTemplate
                    {
                        Name = "Warmup",
                        CompleteButtonText = "Start adding grain",
                        Instructions = "Wait and relax",
                        Target1TempFrom = "strikeTemp",
                        Target2TempFrom = "spargeTemp",
                        ShowTimer = true
                    });
                    db.Add(new BrewStepTemplate
                    {
                        Name = "Add grain",
                        CompleteButtonText = "Start Mash-timer",
                        Instructions = "Add grain to water in the mash kettle",
                        Target1TempFrom = "mashTemp",
                        Target2TempFrom = "spargeTemp",
                        ShowTimer = true
                    });
                    db.Add(new BrewStepTemplate
                    {
                        Name = "Mash",
                        CompleteButtonText = "Start mash-out",
                        Instructions = "Wait for the timer to reach zero. Stir the mash a few times. Pay attention to the temperature",
                        CompleteTimeAdd = "mashTimeInMinutes",
                        Target1TempFrom = "mashTemp",
                        Target2TempFrom = "spargeTemp",
                        ShowTimer = true
                    });
                    db.Add(new BrewStepTemplate
                    {
                        Name = "Mash out",
                        CompleteButtonText = "Start sparge",
                        Instructions = "Wait for the temperature to reach the critical 75,6ºC",
                        Target1TempFrom = "mashOutTemp",
                        Target2TempFrom = "spargeTemp",
                        ShowTimer = true
                    });
                    db.Add(new BrewStepTemplate
                    {
                        Name = "Sparge",
                        CompleteButtonText = "Sparge complete",
                        Instructions = "Add water to the top of the mash kettle.  Transfer wort from the bottom of the mash kettle to the boil kettle",
                        ShowTimer = true
                    });
                    var boilWarmupStep = new BrewStepTemplate
                    {
                        Name = "Boil warmup",
                        CompleteButtonText = "Start Boil-timer",
                        Instructions = "Wait for the wort to boil. Sample OG (before boil). Note the volume of wort before boil. Take the Yiest out of the fridge now",
                        ShowTimer = true
                    };
                    db.Add(boilWarmupStep);
                    db.Add(new BrewStepTemplate
                    {
                        Name = "Boil",
                        CompleteButtonText = "Start Cool-down",
                        Instructions = "Let the wort boil until timer reaches zero. Add hops according to the hop bill. Add yiest nutrition. Add Whirl-flock (15 minutes before end)",
                        CompleteTimeAdd = "boilTimeInMinutes",
                        ShowTimer = true
                    });
                    var cooldownStep = new BrewStepTemplate
                    {
                        Name = "Cooldown",
                        CompleteButtonText = "Cooldown complete",
                        Instructions = "Cool the wort to 18-20ºC. Use whirlpool to gather remains of hop and grain. Clean the yiest tank now",
                        ShowTimer = true
                    };
                    db.Add(cooldownStep);
                    var prepareFermentationStep = new BrewStepTemplate
                    {
                        Name = "Prepare fermentation",
                        CompleteButtonText = "Begin Fermentation",
                        Instructions = "Transfer to yiest tank(bucket). Note the volume of wort. Add o2. Pitch yiest. Clean up. Be happy:)",
                        ShowTimer = true
                    };
                    db.Add(prepareFermentationStep);
                    var fermentationStep = new BrewStepTemplate
                    {
                        Name = "Fermentation",
                        CompleteButtonText = "Archive",
                        Instructions = "Hope. Pray. Dry hop. Whatever.",
                    };
                    db.Add(fermentationStep);
                    db.Add(new BrewStepTemplate
                    {
                        Name = "Archived",
                        Instructions = "Drink goddamnit!"
                    });

                    db.Add(new DataCaptureDefinition
                    {
                        BrewStepTemplate = boilWarmupStep,
                        Label = "OG before boil",
                        ValueType = "int",
                        Optional = false,
                        Units = "SG"
                    });
                    db.Add(new DataCaptureDefinition
                    {
                        BrewStepTemplate = boilWarmupStep,
                        Label = "Wort before boil",
                        ValueType = "float",
                        Optional = false,
                        Units = "l"
                    });
                    db.Add(new DataCaptureDefinition
                    {
                        BrewStepTemplate = cooldownStep,
                        Label = "OG after boil",
                        ValueType = "int",
                        Optional = false,
                        Units = "SG"
                    });
                    db.Add(new DataCaptureDefinition
                    {
                        BrewStepTemplate = prepareFermentationStep,
                        Label = "Wort after boil",
                        ValueType = "float",
                        Optional = false,
                        Units = "l"
                    });
                    db.Add(new DataCaptureDefinition
                    {
                        BrewStepTemplate = prepareFermentationStep,
                        Label = "Wort to yiest tank",
                        ValueType = "float",
                        Optional = false,
                        Units = "l"
                    });
                    db.Add(new DataCaptureDefinition
                    {
                        BrewStepTemplate = fermentationStep,
                        Label = "FG",
                        ValueType = "int",
                        Optional = false,
                        Units = "SG"
                    });

                }
                //db.Database.Migrate();

                // Seed code
                db.SaveChanges();
            }
        }
Beispiel #15
0
        public async Task<int> StartNewBrew([FromBody]SetupDto value)
        {
            using (var db = new BrewMaticContext())
            {
                var repo = new BrewLogRepository(db);

                var brewStep = repo.InitializeNewBrew(value);

                await db.SaveChangesAsync();
                return brewStep.BrewLog.Id;
            }
        }