示例#1
0
            public static SourceItemEntity CreateItem(SourceEntity source,
                                                      DateTime target, int?good, int?total, decimal?measeure,
                                                      DateTime on, string createdBy, SourceGroupEnum group)
            {
                if (measeure.HasValue)
                {
                    if (measeure < 0)
                    {
                        throw new ApplicationException(string.Format("invalid value measure {0} ", measeure));
                    }
                    if (group != SourceGroupEnum.Latency)
                    {
                        if (measeure > 1 || measeure < 0)
                        {
                            throw new ApplicationException(string.Format("proportion {0} must be between 0 and 1", measeure));
                        }
                    }
                }
                else if (good.HasValue && total.HasValue)
                {
                    if (good < 0 || total < 0)
                    {
                        throw new ApplicationException(
                                  string.Format("good {0} and total {1} must be greater equal than zero", good, total));
                    }
                    if (total < good)
                    {
                        throw new ApplicationException(
                                  string.Format("good {0} is greater than total {1}", good, total));
                    }
                    measeure = QualityUtils.CalculateProportion(total, good);
                }
                else
                {
                    throw new ApplicationException($" no values for measures ${total}, ${good}, ${measeure}");
                }

                var entity = new SourceItemEntity()
                {
                    Target     = target,
                    Good       = good,
                    Total      = total,
                    Measure    = measeure.Value,
                    Source     = source,
                    CreatedBy  = createdBy,
                    ModifiedBy = createdBy,
                    CreatedOn  = on,
                    ModifiedOn = on,
                    Group      = group
                };

                return(entity);
            }
示例#2
0
        public async Task <ICollection <SourceItemEntity> > GetSourceItems(int sourceId, SourceGroupEnum group,
                                                                           DateTime start, DateTime end)
        {
            List <SourceItemEntity> result = new List <SourceItemEntity>();

            result = await this.SourcesItems.Where(c => c.SourceId == sourceId && c.Group == group && c.Target >= start && c.Target <= end).ToListAsync();

            return(result);
        }
示例#3
0
 public static SourceItemEntity CreateItemByMeasure(SourceEntity source,
                                                    DateTime target, decimal measure,
                                                    DateTime on, string createdBy, SourceGroupEnum group)
 {
     return(CreateItem(source, target, null, null, measure, on, createdBy, group));
 }
示例#4
0
 public static SourceItemEntity CreateItem(SourceEntity source,
                                           DateTime target, int good, int total,
                                           DateTime on, string createdBy, SourceGroupEnum group)
 {
     return(CreateItem(source, target, good, total, null, on, createdBy, group));
 }
示例#5
0
            public static IEnumerable <SourceItemEntity> CreateItemsFromRange(SourceEntity source,
                                                                              DateTime start, DateTime end, int?good, int?total, decimal?measure,
                                                                              DateTime on, string createdBy, SourceGroupEnum group)
            {
                var result = new List <SourceItemEntity>();
                var days   = (decimal)DateTimeUtils.DaysDiff(end, start);

                if (good.HasValue && total.HasValue)
                {
                    if (good < 0 || total < 0)
                    {
                        throw new ApplicationException(
                                  string.Format("good {0} and total {1} must be greater equal than zero", good, total));
                    }
                    var target_good  = (int)Math.Ceiling(good.Value / days);
                    var target_total = (int)Math.Ceiling(total.Value / days);

                    for (int i = 0; i < days; i++)
                    {
                        var target = start.AddDays(i);
                        var entity = Factory.CreateItem(source,
                                                        target, target_good, target_total, on, createdBy, group);
                        result.Add(entity);
                    }
                }
                else if (measure.HasValue)
                {
                    for (int i = 0; i < days; i++)
                    {
                        var target = start.AddDays(i);
                        var entity = Factory.CreateItem(source,
                                                        target, 0, 0, measure.Value, on, createdBy, group);
                        result.Add(entity);
                    }
                }
                else
                {
                    throw new ApplicationException($" no values for measures ${total}, ${good}, ${measure}");
                }

                return(result);
            }
示例#6
0
 public static IEnumerable <SourceItemEntity> CreateItemsFromRangeByMeasure(SourceEntity source,
                                                                            DateTime start, DateTime end, decimal measure,
                                                                            DateTime on, string createdBy, SourceGroupEnum group)
 {
     return(CreateItemsFromRange(source, start, end, null, null, measure, on, createdBy, group));
 }
示例#7
0
 public static IEnumerable <SourceItemEntity> CreateItemsFromRange(SourceEntity source,
                                                                   DateTime start, DateTime end, int?good, int?total,
                                                                   DateTime on, string createdBy, SourceGroupEnum group)
 {
     return(CreateItemsFromRange(source, start, end, good, total, null, on, createdBy, group));
 }
示例#8
0
        public SourceItemEntity AddSourceItem(int good, int total, DateTime target, DateTime on, string createdBy, SourceGroupEnum group)
        {
            var result = Factory.CreateItem(this, target, good, total, on, createdBy, group);

            this.SourceItems.Add(result);
            return(result);
        }