コード例 #1
0
 public void AddParent(DataPointDto parent)
 {
     base.X = parent.X;
     base.Y = parent.Y;
     base.AssignedClassification = parent.AssignedClassification;
     base.Id = parent.Id;
 }
コード例 #2
0
        protected override async Task OnInitializedAsync()
        {
            int.TryParse(QuestId, out var questId);
            int.TryParse(DataPointId, out var dataPointId);

            DataPoint = await DataPointDataService.GetDataPointForQuest(questId, dataPointId);
        }
コード例 #3
0
        public static List <DataPointDto> CreateDataPointDtos(ModbusUnit modbusUnit)
        {
            List <DataPointDto> dataDataPointDtos = new List <DataPointDto>();

            var modbusUnitNumber = modbusUnit.Number;
            var modulesDic       = modbusUnit.ModulesDic;

            foreach (var module in modulesDic)
            {
                var moduleNumber = module.Key;
                var dpOfmodules  = module.Value.DataPoints;
                foreach (var dpOfm in dpOfmodules)
                {
                    DataPointDto dataPointDto = ConverFrom(dpOfm);
                    dataPointDto.ModuleNumber = moduleNumber;
                    dataPointDto.ModuleName   = module.Value.Name;

                    dataPointDto.ModbusUnitNumber = modbusUnitNumber;
                    dataPointDto.ModbusUnitName   = modbusUnit.Connector.IpAddress.ToString() + ":" + modbusUnit.Connector.Port.ToString();

                    dataDataPointDtos.Add(dataPointDto);
                }
            }

            return(dataDataPointDtos);
        }
コード例 #4
0
 public DataPointLine(DataPointDto dataPoint1, DataPointDto dataPoint2, float offset)
 {
     X1 = dataPoint1.X + offset;
     Y1 = dataPoint1.Y + offset;
     X2 = dataPoint2.X + offset;
     Y2 = dataPoint2.Y + offset;
 }
コード例 #5
0
        public DataPointDto Read()
        {
            if (Position != BinaryFileDao.UnknownOffset)
            {
                Reader.BaseStream.Seek(Position, SeekOrigin.Begin);
            }
            else
            {
                // Save the position of the state information
                Position = Reader.BaseStream.Position;
            }

            DataPointDto dto = new DataPointDto();

            dto.Dao = this;

            dto.Empty = Reader.ReadBoolean();
            if (this.timestampDao == null)
            {
                this.timestampDao = new BinaryFileDateTimeDao(this);
            }
            dto.Timestamp = this.timestampDao.Read();
            dto.Value     = Reader.ReadDouble();

            return(dto);
        }
コード例 #6
0
        public async Task CreateNewDataPoint(DataPointDto dataPointDto)
        {
            var dataPoint = new DataPoint(dataPointDto);

            await Add(dataPoint).ConfigureAwait(true);
            await SaveChanges();
        }
コード例 #7
0
        public IGenericDto ToDto()
        {
            var dataPointDto = new DataPointDto();

            dataPointDto.Id = this.Id;
            dataPointDto.X  = this.X;
            dataPointDto.Y  = this.Y;
            dataPointDto.AssignedClassification = this.AssignedClassification;

            return(dataPointDto);
        }
コード例 #8
0
        public void Push(DataPointDto newDataPointDto)
        {
            if (this.startIndex == -1)
            {
                Debug.Assert(this.endIndex == -1);
                Debug.Assert(this.currentSize == 0);

                // Empty case
                this.startIndex = this.endIndex = 0;
                this.currentSize++;
            }
            else if (this.currentSize < this.maxSize)
            {
                Debug.Assert(this.startIndex == 0);

                // Not full yet case, still filling up prior to wrapping around
                this.endIndex++;
                this.currentSize++;
            }
            else
            {
                Debug.Assert(this.startIndex != this.endIndex);
                Debug.Assert(this.currentSize == this.maxSize);

                // "Full" case, may require wrap around
                this.startIndex++;
                this.endIndex++;

                // Check for wrap around of either start or end
                if (this.endIndex == this.maxSize)
                {
                    this.endIndex = 0;
                }
                else if (this.startIndex == this.maxSize)
                {
                    this.startIndex = 0;
                }
            }

            Debug.Assert(GetAt(this.endIndex) != null);

            BinaryFileDataPointDao dataPointDao = GetAt(this.endIndex);

            // The data point DAO must know where it is on disk from when it was either created or read
            Debug.Assert(dataPointDao.Position != BinaryFileDao.UnknownOffset);
            dataPointDao.Write(newDataPointDto);
            newDataPointDto.Dao = (IDataPointDao)dataPointDao;

            // Write the updated archive state back to disk
            WriteState();
        }
コード例 #9
0
        public static DataPointDto ConverFrom(DataPoint dataPoint)
        {
            DataPointDto dpDto = new DataPointDto();

            dpDto.Number               = dataPoint.Number;
            dpDto.Name                 = dataPoint.Name;
            dpDto.DeviceAddress        = dataPoint.DeviceAddress;
            dpDto.StartRegisterAddress = dataPoint.StartRegisterAddress;
            dpDto.DataPointDataType    = dataPoint.DataPointDataType;
            dpDto.DataPointType        = dataPoint.DataPointType;
            dpDto.Description          = dataPoint.Description;
            dpDto.RealTimeValue        = dataPoint.RealTimeValue;
            dpDto.ValueToSet           = dataPoint.ValueToSet;

            return(dpDto);
        }
コード例 #10
0
        private void ReadDataPoints()
        {
            ReadState();

            BinaryFileDataPointDao[] unorderedDataPointDao = new BinaryFileDataPointDao[this.dto.MaxDataPoints];
            DataPointDto[]           unorderedDataPointDto = new DataPointDto[this.dto.MaxDataPoints];

            // Read the whole array of data points into unordered list
            for (int i = 0; i < this.dto.MaxDataPoints; i++)
            {
                BinaryFileDataPointDao newDataPointDao = new BinaryFileDataPointDao(archiveDao);
                DataPointDto           newDataPointDto = newDataPointDao.Read();
                newDataPointDto.Dao      = (IDataPointDao)newDataPointDao;
                unorderedDataPointDao[i] = newDataPointDao;
                unorderedDataPointDto[i] = newDataPointDto;
            }

            if (this.startIndex != UnknownIndex)
            {
                // Read from the first data point to the end of the array
                for (int i = this.startIndex; i < this.dto.MaxDataPoints; i++)
                {
                    this.dataPoints.Add(unorderedDataPointDao[i]);
                    if (unorderedDataPointDto[i].Empty != true)
                    {
                        this.dto.Add(unorderedDataPointDto[i]);
                    }
                }

                // Read from the beginning of the array to the end of the wrap around
                for (int i = 0; i < this.startIndex; i++)
                {
                    this.dataPoints.Add(unorderedDataPointDao[i]);
                    if (unorderedDataPointDto[i].Empty != true)
                    {
                        this.dto.Add(unorderedDataPointDto[i]);
                    }
                }
            }
            else
            {
                for (int i = 0; i < this.dto.MaxDataPoints; i++)
                {
                    this.dataPoints.Add(unorderedDataPointDao[i]);
                }
            }
        }
コード例 #11
0
        private void CreateEmptyDataPoints(DataPointCircularQueueDto dto)
        {
            Debug.Assert(dto.MaxDataPoints >= dto.DataPoints.Length);

            // Write out the balance of empty data points
            for (int i = 0; i < dto.MaxDataPoints; i++)
            {
                DataPointDto emptyDataPointDto = new DataPointDto();
                emptyDataPointDto.Empty     = true;
                emptyDataPointDto.Timestamp = DateTime.Now;
                emptyDataPointDto.Value     = Double.NaN;

                BinaryFileDataPointDao dataPointDao = new BinaryFileDataPointDao(this.archiveDao);
                dataPointDao.Write(emptyDataPointDto);
                this.dataPoints.Add(dataPointDao);
            }
        }
コード例 #12
0
        public static DataPointDto ConvertToDataPointInfoView(this DataPointViewModel dataPointViewModel)
        {
            DataPointDto dpDto = new DataPointDto();

            dpDto.Id                   = dataPointViewModel.Id;
            dpDto.Number               = dataPointViewModel.Number;
            dpDto.Name                 = dataPointViewModel.Name;
            dpDto.DeviceAddress        = dataPointViewModel.DeviceAddress;
            dpDto.StartRegisterAddress = dataPointViewModel.StartRegisterAddress;
            dpDto.DataPointDataType    = dataPointViewModel.DataPointDataType;
            dpDto.DataPointType        = dataPointViewModel.DataPointType;
            dpDto.RealTimeValue        = dataPointViewModel.RealTimeValue;
            dpDto.ValueToSet           = dataPointViewModel.ValueToSet;

            dpDto.ModuleNumber = dataPointViewModel.ModuleNumber;
            dpDto.ModuleName   = dataPointViewModel.ModuleName;

            dpDto.ModbusUnitNumber = dataPointViewModel.ModbusUnitNumber;

            return(dpDto);
        }
コード例 #13
0
        public static DataPointViewModel ConvertToDataPointViewModel(this DataPointDto dataPointDto)
        {
            DataPointViewModel dpVm = new DataPointViewModel();

            dpVm.Id                   = dataPointDto.Id;
            dpVm.Number               = dataPointDto.Number;
            dpVm.Name                 = dataPointDto.Name;
            dpVm.DeviceAddress        = dataPointDto.DeviceAddress;
            dpVm.StartRegisterAddress = dataPointDto.StartRegisterAddress;
            dpVm.DataPointDataType    = dataPointDto.DataPointDataType;
            dpVm.DataPointType        = dataPointDto.DataPointType;
            dpVm.RealTimeValue        = dataPointDto.RealTimeValue;
            dpVm.ValueToSet           = dataPointDto.ValueToSet;

            dpVm.ModuleNumber     = dataPointDto.ModuleNumber;
            dpVm.ModuleName       = dataPointDto.ModuleName;
            dpVm.ModbusUnitNumber = dataPointDto.ModbusUnitNumber;
            dpVm.ModbusUnitName   = dataPointDto.ModbusUnitName;

            return(dpVm);
        }
コード例 #14
0
        public void Write(DataPointDto dto)
        {
            if (Position == BinaryFileDao.UnknownOffset)
            {
                Writer.Seek(0, SeekOrigin.End);
                // Record where the data point has been written
                Position = Writer.BaseStream.Position;
            }
            else
            {
                // Go to the location of the datum in the file
                Writer.BaseStream.Seek((int)Position, SeekOrigin.Begin);
            }

            Writer.Write(dto.Empty);
            if (this.timestampDao == null)
            {
                this.timestampDao = new BinaryFileDateTimeDao(this);
            }
            this.timestampDao.Create(dto.Timestamp);
            Writer.Write(dto.Value);
        }
コード例 #15
0
        public static List <DataPointDto> ReadFromFileDto()
        {
            if (!File.Exists(_path))
            {
                File.Create(_path);
            }

            try
            {
                var dataPoints = new List <DataPointDto>();

                string[] lines = File.ReadAllLines(_path);

                foreach (var line in lines)
                {
                    DataPointDto pointDto = new DataPointDto();
                    string[]     numbers  = line.Split(' ');
                    if (numbers.Count() > 1)
                    {
                        pointDto.X = float.Parse(numbers[0]);
                        pointDto.Y = float.Parse(numbers[1]);
                        if (numbers.Count() > 2 && numbers[2] != "")
                        {
                            pointDto.AssignedClassification = Int32.Parse(numbers[2]);
                        }
                        dataPoints.Add(pointDto);
                    }
                }

                return(dataPoints);
            }
            catch
            {
                throw new Exception("Invalid data");
            }
        }
コード例 #16
0
 public void Create(DataPointDto dto)
 {
     Write(dto);
 }
コード例 #17
0
 public DataPoint(DataPointDto dataPointDto)
 {
     FromDto(dataPointDto);
 }
コード例 #18
0
            public async Task <Result> Handle(Query request, CancellationToken cancellationToken)
            {
                var budgetCategoryIdsQuery = _accessControlService.GetAccessibleBudgetCategoryIds(request.BudgetId, request.BudgetCategoryType);

                if (request.BudgetCategoryIds != null && request.BudgetCategoryIds.Any())
                {
                    budgetCategoryIdsQuery = budgetCategoryIdsQuery.Where(x => request.BudgetCategoryIds.Any(s => s == x));
                }

                var budgetCurrency = _readDb.Budgets.First(x => x.BudgetId == request.BudgetId).Currency;

                var budgetCategoryIds = budgetCategoryIdsQuery.ToList();
                var budgetCategories  = _readDb.BudgetCategories.Where(x => budgetCategoryIds.Contains(x.BudgetCategoryId)).ToList();

                var query = _readDb.Transactions.Where(x => budgetCategoryIds.Contains(x.BudgetCategoryId));

                query = query.Where(x => x.TransactionDate >= request.TransactionDateStart.Date && x.TransactionDate <= request.TransactionDateEnd.Date);


                var transactions = await query.ToListAsync(cancellationToken);

                if (!transactions.Any())
                {
                    return(new Result());
                }

                var timelinePeriod = new DateRange(request.TransactionDateStart, request.TransactionDateEnd);

                var periods = request.GroupingStep switch
                {
                    eGroupingStep.Day => timelinePeriod.Start.EachDayTo(timelinePeriod.End),
                    eGroupingStep.Year => timelinePeriod.Start.EachYearTo(timelinePeriod.End),
                    eGroupingStep.Month => timelinePeriod.Start.EachMonthTo(timelinePeriod.End),
                    eGroupingStep.Quarter => timelinePeriod.Start.EachQuarterTo(timelinePeriod.End),
                    eGroupingStep.Week => timelinePeriod.Start.EachWeekTo(timelinePeriod.End, CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek),
                    _ => throw new ArgumentOutOfRangeException()
                };

                var dateRanges = transactions.GroupBy(x => periods.FirstOrDefault(s => s.Contains(x.TransactionDate)))
                                 .Select(periodGroup =>
                {
                    var period = periodGroup.Key;

                    var categoryDataPoints = budgetCategories.Select(category =>
                    {
                        var categoryId     = category.BudgetCategoryId;
                        var categoryAmount = periodGroup.Where(s => s.BudgetCategoryId == categoryId)
                                             .Select(s => s.Amount + s.SubTransactions.Select(t => t.Amount).Aggregate(new MoneyAmount(budgetCurrency.CurrencyCode, 0), (a, b) => a + b))
                                             .Aggregate(new MoneyAmount(budgetCurrency.CurrencyCode, 0), (a, b) => a + b);

                        return(new BudgetCategoryDataPointDto()
                        {
                            DateRange = period,
                            BudgetCategoryId = categoryId,
                            Key = period.ToString(),
                            AmountTotal = categoryAmount
                        });
                    })
                                             .ToList();

                    var totalAmount = categoryDataPoints.Select(x => x.AmountTotal)
                                      .Aggregate(new MoneyAmount(budgetCurrency.CurrencyCode, 0), (a, b) => a + b);

                    return(new DateRangeData()
                    {
                        DateRange = period,
                        Key = period.ToString(),
                        BudgetCategories = categoryDataPoints,
                        Total = new DataPointDto()
                        {
                            DateRange = period,
                            Key = period.ToString(),
                            AmountTotal = totalAmount
                        }
                    });
                })
                                 .OrderByDescending(x => x.DateRange.Start)
                                 .ToList();

                if (dateRanges.Count > 1)
                {
                    for (var i = 0; i < dateRanges.Count - 1; i++)
                    {
                        var current  = dateRanges[i];
                        var previous = dateRanges[i + 1];

                        foreach (var budgetCategoryDataPoint in current.BudgetCategories)
                        {
                            var previousBudgetCategoryDataPoint = previous.BudgetCategories.FirstOrDefault(x => x.BudgetCategoryId == budgetCategoryDataPoint.BudgetCategoryId);
                            if (previousBudgetCategoryDataPoint == null)
                            {
                                continue;
                                ;
                            }

                            budgetCategoryDataPoint.AmountTotalChange = previousBudgetCategoryDataPoint.AmountTotal.Amount > 0
                                                                            ? (budgetCategoryDataPoint.AmountTotal.Amount - previousBudgetCategoryDataPoint.AmountTotal.Amount) / previousBudgetCategoryDataPoint.AmountTotal.Amount
                                                                            : (decimal?)null;

                            budgetCategoryDataPoint.AmountPerDayChange = previousBudgetCategoryDataPoint.AmountPerDay.Amount > 0
                                                                             ? (budgetCategoryDataPoint.AmountPerDay.Amount - previousBudgetCategoryDataPoint.AmountPerDay.Amount) / previousBudgetCategoryDataPoint.AmountPerDay.Amount
                                                                             : (decimal?)null;

                            budgetCategoryDataPoint.AmountPerWeekChange = previousBudgetCategoryDataPoint.AmountPerWeek.Amount > 0
                                                                              ? (budgetCategoryDataPoint.AmountPerWeek.Amount - previousBudgetCategoryDataPoint.AmountPerWeek.Amount) / previousBudgetCategoryDataPoint.AmountPerWeek.Amount
                                                                              : (decimal?)null;

                            budgetCategoryDataPoint.AmountPerMonthChange = previousBudgetCategoryDataPoint.AmountPerMonth.Amount > 0
                                                                               ? (budgetCategoryDataPoint.AmountPerMonth.Amount - previousBudgetCategoryDataPoint.AmountPerMonth.Amount) / previousBudgetCategoryDataPoint.AmountPerMonth.Amount
                                                                               : (decimal?)null;
                        }

                        current.Total.AmountTotalChange = previous.Total.AmountTotal.Amount > 0
                                                              ? (current.Total.AmountTotal.Amount - previous.Total.AmountTotal.Amount) / previous.Total.AmountTotal.Amount
                                                              : (decimal?)null;
                        current.Total.AmountPerDayChange = previous.Total.AmountTotal.Amount > 0
                                                               ? (current.Total.AmountPerDay.Amount - previous.Total.AmountPerDay.Amount) / previous.Total.AmountPerDay.Amount
                                                               : (decimal?)null;
                        current.Total.AmountPerWeekChange = previous.Total.AmountTotal.Amount > 0
                                                                ? (current.Total.AmountPerWeek.Amount - previous.Total.AmountPerWeek.Amount) / previous.Total.AmountPerWeek.Amount
                                                                : (decimal?)null;
                        current.Total.AmountPerMonthChange = previous.Total.AmountTotal.Amount > 0
                                                                 ? (current.Total.AmountPerMonth.Amount - previous.Total.AmountPerMonth.Amount) / previous.Total.AmountPerMonth.Amount
                                                                 : (decimal?)null;
                    }
                }

                var budgetCategoryTotals = dateRanges.SelectMany(x => x.BudgetCategories)
                                           .GroupBy(x => x.BudgetCategoryId)
                                           .Select(x => new BudgetCategoryDataPointDto()
                {
                    Key              = timelinePeriod.ToString(),
                    DateRange        = timelinePeriod,
                    BudgetCategoryId = x.Key,
                    AmountTotal      = x.Select(s => s.AmountTotal)
                                       .Aggregate(new MoneyAmount(budgetCurrency.CurrencyCode, 0), (a, b) => a + b)
                })
                                           .ToList();
                var total = new DataPointDto()
                {
                    DateRange   = timelinePeriod,
                    Key         = timelinePeriod.ToString(),
                    AmountTotal = budgetCategoryTotals.Select(x => x.AmountTotal)
                                  .Aggregate(new MoneyAmount(budgetCurrency.CurrencyCode, 0), (a, b) => a + b)
                };

                return(new Result()
                {
                    Data = new ResponseDto()
                    {
                        DateRanges = dateRanges,
                        BudgetCategoryTotals = budgetCategoryTotals,
                        Total = total
                    }
                });
            }
        }
コード例 #19
0
 public ColoredDataPoint(DataPointDto parent)
 {
     AddParent(parent);
 }