Exemple #1
0
        public async Task DeleteCycleStep(string cycleStepId)
        {
            CycleStep cycleStepToDelete = unitOfWork.GetById <CycleStep>(cycleStepId);
            await unitOfWork.DeleteWhere <CycleStep>(x => x.Id == cycleStepId);

            await UpdateStepNumbersOnDelete(cycleStepToDelete);
        }
Exemple #2
0
        public async Task CreateOrUpdateCycleStep(CycleStepItemViewModel cycleStepItemViewModel)
        {
            CycleStep cycleStepToInsertOrUpdate;

            if (cycleStepItemViewModel.IsNew)
            {
                cycleStepToInsertOrUpdate = new CycleStep();

                SynthesisCycle synthesisCycle = unitOfWork.GetById <SynthesisCycle>(cycleStepItemViewModel.SynthesisCycleId);
                cycleStepToInsertOrUpdate.SynthesisCycle = synthesisCycle;

                await MapCycleStepItemToCycleStep(cycleStepItemViewModel, cycleStepToInsertOrUpdate);
            }
            else
            {
                cycleStepToInsertOrUpdate = await unitOfWork.GetAll <CycleStep>()
                                            .Include(x => x.SynthesisCycle)
                                            .Include(x => x.HardwareFunction)
                                            .SingleAsync(x => x.Id == cycleStepItemViewModel.CycleStepId);

                await MapCycleStepItemToCycleStep(cycleStepItemViewModel, cycleStepToInsertOrUpdate);
            }

            unitOfWork.InsertOrUpdate(cycleStepToInsertOrUpdate);
            unitOfWork.Commit();

            if (cycleStepItemViewModel.IsNew)
            {
                await UpdateStepNumbersOnInsert(cycleStepItemViewModel, cycleStepToInsertOrUpdate);
            }
        }
        private bool IsCycleStepApplicable(char nucleotide, CycleStep cycleStep)
        {
            bool isCycleStepApplicable = (nucleotide == 'A' && cycleStep.A) ||
                                         (nucleotide == 'C' && cycleStep.C) ||
                                         (nucleotide == 'G' && cycleStep.G) ||
                                         (nucleotide == 'T' && cycleStep.T);

            return(isCycleStepApplicable);
        }
Exemple #4
0
        public CycleStep CreateCycleStep()
        {
            CycleStep cycleStep = new CycleStep()
            {
                Number           = 1,
                StepTime         = 3,
                SynthesisCycle   = CreateSynthesisCycle(),
                HardwareFunction = CreateHardwareFunction()
            };

            return(GetOrCreate(() => cycleStep));
        }
Exemple #5
0
        private async Task UpdateStepNumbersOnDelete(CycleStep cycleStepToDelete)
        {
            IEnumerable <CycleStep> cycleSteps = await unitOfWork.GetAll <CycleStep>()
                                                 .Include(x => x.SynthesisCycle)
                                                 .Include(x => x.HardwareFunction)
                                                 .Where(x => x.SynthesisCycleId == cycleStepToDelete.SynthesisCycleId &&
                                                        x.Number > cycleStepToDelete.Number)
                                                 .OrderBy(x => x.Number)
                                                 .ToListAsync();

            foreach (CycleStep cycleStep in cycleSteps)
            {
                cycleStep.Number--;
            }

            unitOfWork.Commit();
        }
Exemple #6
0
        public async Task CreateOrUpdateSynthesisCycle(SynthesisCycleItemViewModel synthesisCycleItemViewModel)
        {
            SynthesisCycle synthesisCycle;

            if (string.IsNullOrWhiteSpace(synthesisCycleItemViewModel.Id))
            {
                var  currentPrincipal = identityStorage.GetPrincipal();
                User currentUser      = unitOfWork.GetById <User>(currentPrincipal.UserId);

                synthesisCycle      = new SynthesisCycle();
                synthesisCycle.Name = synthesisCycleItemViewModel.Name;
                synthesisCycle.User = currentUser;

                SynthesisCycle defaultSynthesisCycle = await unitOfWork.GetAll <SynthesisCycle>()
                                                       .Include(x => x.CycleSteps)
                                                       .Include(x => x.CycleSteps.Select(y => y.HardwareFunction))
                                                       .SingleAsync(x => x.UserId == null);

                foreach (CycleStep defaultCycleStep in defaultSynthesisCycle.CycleSteps)
                {
                    CycleStep newCycleStep = new CycleStep();
                    newCycleStep.Number           = defaultCycleStep.Number;
                    newCycleStep.StepTime         = defaultCycleStep.StepTime;
                    newCycleStep.A                = defaultCycleStep.A;
                    newCycleStep.G                = defaultCycleStep.G;
                    newCycleStep.C                = defaultCycleStep.C;
                    newCycleStep.T                = defaultCycleStep.T;
                    newCycleStep.Six              = defaultCycleStep.Six;
                    newCycleStep.Seven            = defaultCycleStep.Seven;
                    newCycleStep.SafeStep         = defaultCycleStep.SafeStep;
                    newCycleStep.HardwareFunction = defaultCycleStep.HardwareFunction;

                    synthesisCycle.CycleSteps.Add(newCycleStep);
                }
            }
            else
            {
                synthesisCycle = await unitOfWork.GetAll <SynthesisCycle>().Include(x => x.User).SingleAsync(x => x.Id == synthesisCycleItemViewModel.Id);

                synthesisCycle.Name = synthesisCycleItemViewModel.Name;
            }

            unitOfWork.InsertOrUpdate(synthesisCycle);
            unitOfWork.Commit();
        }
    public void NotifyStep(CycleStep step)
    {
        string board = "";
        int    n     = Board.B.N;

        for (int i = 0; i < n; ++i)
        {
            for (int j = 0; j < n; ++j)
            {
                int   idx  = i * n + j;
                Being b    = Board.B.Get(idx);
                char  mark = ' ';
                if (b != null)
                {
                    switch (b.Health)
                    {
                    case Being.HealthStatus.HEALTHY:
                        mark = 'H';
                        break;

                    case Being.HealthStatus.IMUNE:
                        mark = 'I';
                        break;

                    case Being.HealthStatus.INFECTED:
                        mark = 'X';
                        break;

                    case Being.HealthStatus.PSEUDOIMUNE:
                        mark = 'P';
                        break;
                    }
                }
                board += mark;
            }
            board += '\n';
        }
        string msg = string.Format(
            "<color=blue>Step {0} =></color> H:{1} I:{2} P:{3} X:{4} [i:{5} d:{6} c:{7} b:{8}]",
            step.num, step.healthies, step.imunes, step.pseudoimunes, step.infected,
            step.infections, step.agedeads, step.casualties, step.newborns
            );

        Debug.Log(board + "\n" + msg);
    }
Exemple #8
0
    void UpdateInfo(CycleStep step)
    {
        textStepNum.text        = "Passo: " + step.num;
        textTotalHealthy.text   = step.healthies + " saudáveis.";
        textTotalImunes.text    = step.imunes + " imunes.";
        textTotalInfection.text = step.infected + " infectados.";
        textTotalPseudo.text    = step.pseudoimunes + " pseudoimunes.";
        textTotalGraves.text    = step.dead + " mortos.";
        textStepInfection.text  = step.infections + " novos infectados.";
        textStepDeadbyAge.text  = step.agedeads + " mortos por idade.";
        textStepCasualties.text = step.casualties + " mortos por acidente.";
        textStepBirths.text     = step.newborns + " novos nascidos.";

        textInfectionChances.text = string.Format("Chances de infecção: {0}%", config.sliderInfectionChance.slider.value);
        textAccidentChances.text  = string.Format("Chances de acidentes: {0}%", config.sliderAccidentChance.slider.value);
        textBirthChances.text     = string.Format("Chances de nascimentos: {0}%", config.sliderBirthChance.slider.value);
        //textFrequency.text = string.Format("Frequência: {0} Hz", config.sliderFrequency.slider.value);
    }
Exemple #9
0
        private void Process(DataRow row)
        {
            var step = row.State != null?StateToCycleStep(row.State) : CurrentToCycleStep(row.Current);

            if (step != _currStep)
            {
                if (step != CycleStep.Rest)
                {
                    if (_steps.Contains(step) && Math.Abs(row.Capacity) <= CapacityThreshold)
                    {
                        _cycleIndex += 1;
                        _steps.Clear();
                    }

                    _steps.Add(step);
                }

                _currStep = step;
            }

            if (_startDateTime == null)
            {
                _startDateTime = row.TestTime;
            }

            var dataPoint = new DataPoint
            {
                CycleStep   = step,
                CycleIndex  = _cycleIndex,
                Time        = (row.TestTime - _startDateTime.Value).TotalSeconds,
                Current     = row.Current,
                Voltage     = row.Voltage,
                Capacity    = row.Capacity,
                Energy      = row.Capacity * row.Voltage,
                Power       = row.Current * row.Voltage,
                Temperature = row.Temperature
            };

            Push(_currentChannelIndex, dataPoint);
        }
Exemple #10
0
        private string GetCycleStepApiUrl(CycleStep cycleStep, char nucleotide, IEnumerable <HardwareFunction> bAndTetToColFunctions)
        {
            string cycleStepApiUrl = cycleStep.HardwareFunction.ApiUrl;

            if (cycleStep.HardwareFunction.FunctionType == HardwareFunctionType.BAndTetToCol)
            {
                switch (nucleotide)
                {
                case 'A':
                    cycleStepApiUrl = bAndTetToColFunctions
                                      .Single(x => x.FunctionType == HardwareFunctionType.AAndTetToCol)
                                      .ApiUrl;
                    break;

                case 'C':
                    cycleStepApiUrl = bAndTetToColFunctions
                                      .Single(x => x.FunctionType == HardwareFunctionType.CAndTetToCol)
                                      .ApiUrl;
                    break;

                case 'T':
                    cycleStepApiUrl = bAndTetToColFunctions
                                      .Single(x => x.FunctionType == HardwareFunctionType.TAndTetToCol)
                                      .ApiUrl;
                    break;

                case 'G':
                    cycleStepApiUrl = bAndTetToColFunctions
                                      .Single(x => x.FunctionType == HardwareFunctionType.GAndTetToCol)
                                      .ApiUrl;
                    break;
                }
            }

            return(cycleStepApiUrl);
        }
Exemple #11
0
        private async Task MapCycleStepItemToCycleStep(CycleStepItemViewModel cycleStepItemViewModel, CycleStep cycleStep)
        {
            cycleStep.Number   = cycleStepItemViewModel.StepNumber != 0 ? cycleStepItemViewModel.StepNumber : 1;
            cycleStep.StepTime = cycleStepItemViewModel.StepTime;
            cycleStep.A        = cycleStepItemViewModel.A;
            cycleStep.G        = cycleStepItemViewModel.G;
            cycleStep.C        = cycleStepItemViewModel.C;
            cycleStep.T        = cycleStepItemViewModel.T;
            cycleStep.T        = cycleStepItemViewModel.T;
            cycleStep.Six      = cycleStepItemViewModel.Six;
            cycleStep.Seven    = cycleStepItemViewModel.Seven;
            cycleStep.SafeStep = cycleStepItemViewModel.SafeStep;

            if (string.IsNullOrWhiteSpace(cycleStepItemViewModel.HardwareFunction?.Id))
            {
                cycleStep.HardwareFunction = await unitOfWork.GetAll <HardwareFunction>()
                                             .SingleAsync(x => x.FunctionType == HardwareFunctionType.BAndTetToCol);
            }
            else if (cycleStep.HardwareFunctionId != cycleStepItemViewModel.HardwareFunction.Id)
            {
                cycleStep.HardwareFunction = unitOfWork.GetById <HardwareFunction>(cycleStepItemViewModel.HardwareFunction.Id);
            }
        }
Exemple #12
0
        private async Task UpdateStepNumbersOnInsert(CycleStepItemViewModel cycleStepItemViewModel, CycleStep cycleStepToInsertOrUpdate)
        {
            bool cycleStepWithTheSameNumberExists = await unitOfWork.GetAll <CycleStep>()
                                                    .CountAsync(x => x.SynthesisCycleId == cycleStepItemViewModel.SynthesisCycleId && x.Number == cycleStepToInsertOrUpdate.Number) > 1;

            if (cycleStepWithTheSameNumberExists)
            {
                IEnumerable <CycleStep> cycleSteps = await unitOfWork.GetAll <CycleStep>()
                                                     .Include(x => x.SynthesisCycle)
                                                     .Include(x => x.HardwareFunction)
                                                     .Where(x => x.SynthesisCycleId == cycleStepItemViewModel.SynthesisCycleId &&
                                                            x.Number >= cycleStepToInsertOrUpdate.Number && x.Id != cycleStepToInsertOrUpdate.Id)
                                                     .OrderBy(x => x.Number)
                                                     .ToListAsync();

                foreach (CycleStep cycleStep in cycleSteps)
                {
                    cycleStep.Number++;
                }

                unitOfWork.Commit();
            }
        }
Exemple #13
0
 public void NotifyStep(CycleStep step)
 {
     UpdateInfo(step);
 }
Exemple #14
0
        private void Process(DataRow row)
        {
            if (_prev != null && _prev.StepIndex != row.StepIndex && _isChargeHappened && _isDischargeHappened)
            {
                _cycleIndex++;
                _isChargeHappened    = false;
                _isDischargeHappened = false;
            }

            if (_startDateTime == null)
            {
                _startDateTime = row.DateTime;
            }

            CycleStep cycleStep = StepNameToCycleStep(row.StateCode);

            if (_prev != null && _prev.StepIndex != row.StepIndex)
            {
                if (cycleStep == CycleStep.ChargeCC || cycleStep == CycleStep.ChargeCV)
                {
                    _isChargeHappened = true;
                }
                else if (cycleStep == CycleStep.Discharge)
                {
                    _isDischargeHappened = true;
                }
            }

            DataPoint dataPoint = new DataPoint
            {
                CycleIndex  = _cycleIndex,
                CycleStep   = cycleStep,
                Time        = (row.DateTime - _startDateTime.Value).TotalSeconds,
                Current     = 1000 * row.Current,
                Voltage     = row.Voltage,
                Capacity    = 1000 * row.Capacity,
                Power       = (1000 * row.Current) * row.Voltage,
                Temperature = row.Temperature
            };

            if (cycleStep == CycleStep.ChargeCC || cycleStep == CycleStep.ChargeCV)
            {
                if (mWhEnergyMultiplier)
                {
                    //milliwatt-hour (mWh) to Watt-hour (Wh), mWh = Wh * 1000
                    dataPoint.Energy = row.Energy / 1000;
                }
                else
                {
                    dataPoint.Energy = row.Energy;
                }
            }
            else if (cycleStep == CycleStep.Discharge)
            {
                if (mWhEnergyMultiplier)
                {
                    //milliwatt-hour (mWh) to Watt-hour (Wh), mWh = Wh * 1000
                    dataPoint.DischargeEnergy = row.Energy / 1000;
                }
                else
                {
                    dataPoint.DischargeEnergy = row.Energy;
                }
            }

            Push(_currentChannelIndex, dataPoint);
            _prev = row;
        }
Exemple #15
0
 public void NotifyStep(CycleStep step)
 {
     UIRefresh();
 }