Пример #1
0
        public IDictionary <string, DateValues> GetData(IList <string> deviceCodes = null, IList <string> properties = null)
        {
            Logger.Debug($"Db Manager GetData Invoked for (code: {deviceCodes} properties {properties})");
            IDictionary <string, DateValues> telemetiesData = new Dictionary <string, DateValues>();

            if (properties == null)
            {
                return(telemetiesData);
            }
            int err = DbReader.GetTelemetries(out IDictionary <string, IList <(string propCode, string timeMarker, string propValue)> > propertiesData, deviceCodes, properties);

            if (err != 0 || propertiesData.Count == 0)
            {
                return(null);
            }
            var dataValues = new DateValues(propertiesData.Count);

            foreach (var propertyData in propertiesData)
            {
                foreach (var value in propertyData.Value)
                {
                    dataValues.Add((value.propValue, value.timeMarker.TimeFormater()));
                }
                telemetiesData.Add(propertyData.Key, dataValues);
            }

            return(telemetiesData);
        }
        public void InfillMissingValues()
        {
            StartDate = DateValues.FirstOrDefault();
            EndDate   = DateValues.LastOrDefault();
            var count = EndDate.DateInt - StartDate.DateInt + 1;
            var list  = new List <double?>(new double?[count]);

            if (DateValues != null)
            {
                var currentIndex = 0;
                for (var i = 0; i < count; ++i)
                {
                    var dateInt = StartDate.DateInt + i;
                    if (dateInt == DateValues[currentIndex].DateInt)
                    {
                        list[i] = DailyValues[currentIndex++];
                    }
                    else
                    {
                        list[i] = null;
                    }
                }
            }
            DateValues  = null;
            DailyValues = list;
        }
Пример #3
0
        public override bool IsValid(object value)
        {
            DateValues dateValues = (DateValues)value;
            DateTime   date       = dateValues.Date.Add(dateValues.Time.TimeOfDay);

            if (date > DateTime.Now)
            {
                return(true);
            }
            return(false);
        }
Пример #4
0
        public GetGraficoAssistenciaMensal ObterAssistenciasMensal(int congregacaoId)
        {
            string[]  background  = { "rgba(75, 112, 0, 0.6)", "rgba(0, 3, 205, 0.6)" };
            string[]  borderColor = { "rgba(75, 112, 0, 1)", "rgba(0, 3, 205, 1)" };
            const int borderWidth = 1;

            using (RepositorySession dalSession = new RepositorySession(Runtime.JWInstance))
            {
                IUnitOfWork unitOfWork = dalSession.UnitOfWork;
                try
                {
                    var congregacao = _repositoryCongregacao.ListAll(ref unitOfWork).FirstOrDefault(x => x.Codigo == congregacaoId);
                    var ret         = _repository.ObterAssistenciasMensal(ref unitOfWork, congregacaoId);
                    var model       = new GetGraficoAssistenciaMensal
                    {
                        Labels   = new List <string>(),
                        Datasets = new List <Dataset>()
                    };
                    var label = "";

                    for (int i = 0; i < ret.Count; i++)
                    {
                        label = DateValues.ObterMesPortugues(ret[i].Mes, ret[i].Ano);
                        if (!model.Labels.Contains(label))
                        {
                            model.Labels.Add(label);
                        }

                        if (!model.Datasets.Any(x => x.Label == DateValues.ObterDiaSemanaPortugues(ret[i].DiaReuniao)))
                        {
                            model.Datasets.Add(new Dataset
                            {
                                BackgroundColor = (ret[i].DiaReuniao == congregacao.DiaReuniaoServico) ? background[0] : background[1],
                                BorderColor     = (ret[i].DiaReuniao == congregacao.DiaReuniaoServico) ? borderColor[0] : borderColor[1],
                                BorderWidth     = borderWidth,
                                Label           = DateValues.ObterDiaSemanaPortugues(ret[i].DiaReuniao),
                                Data            = ret.Where(x => x.DiaReuniao == ret[i].DiaReuniao).Select(c => c.AssistenciaTotal / c.QuantidadeReunioes).ToList()
                            });
                        }
                    }

                    return(model);
                }
                catch
                {
                    throw;
                }
            }
        }
 public RangeRequest(int fromDay, int fromMonth, int fromYear, int toDay, int toMonth, int toYear)
 {
     To = new DateValues
     {
         Day   = toDay,
         Month = toMonth,
         Year  = toYear
     };
     From = new DateValues
     {
         Day   = fromDay,
         Month = fromMonth,
         Year  = fromYear
     };
 }
Пример #6
0
        /// <summary>
        /// Returns true if the class is active on the specified date, based on the class Start/End dates. Does not factor in whether the semester is actually active on these dates.
        /// </summary>
        /// <param name="date"></param>
        /// <returns></returns>
        public bool IsActiveOnDate(DateTime date)
        {
            // If class hasn't started yet
            if (!DateValues.IsUnassigned(StartDate) && StartDate > date.Date)
            {
                return(false);
            }

            // If class is already over
            if (!DateValues.IsUnassigned(EndDate) && date.Date > EndDate)
            {
                return(false);
            }

            return(true);
        }
        public async override void RefreshView()
        {
            DateValues.Clear();
            PortfolioValues.Clear();

            // Determine frequency to use
            var valueFrequency = ValueFrequency.Daily;
            var timeSpan       = _Parameter.DateRange.ToDate - _Parameter.DateRange.FromDate;

            if (timeSpan.Days > 365 * 5)
            {
                valueFrequency = ValueFrequency.Monthly;
            }
            else if (timeSpan.Days > 365)
            {
                valueFrequency = ValueFrequency.Weekly;
            }

            PortfolioValueResponse response;

            if (_Parameter.Stock.Id == Guid.Empty)
            {
                response = await _Parameter.RestClient.Portfolio.GetValue(_Parameter.DateRange, valueFrequency);
            }
            else
            {
                response = await _Parameter.RestClient.Holdings.GetValue(_Parameter.Stock.Id, _Parameter.DateRange, valueFrequency);
            }
            if (response == null)
            {
                return;
            }

            // create chart data
            var values = new List <double>();

            foreach (var value in response.Values)
            {
                DateValues.Add(value.Date.ToShortDateString());
                values.Add((double)value.Amount);
            }

            PortfolioValues.AddRange(values);
        }
Пример #8
0
        public static DateTime ToViewItemTime(AccountDataItem account, DateTime rawDateTime)
        {
            try
            {
                if (account.SchoolTimeZone == null || DateValues.IsUnassigned(rawDateTime) || rawDateTime == DateValues.NO_DUE_DATE || rawDateTime == SqlDate.MinValue || rawDateTime == SqlDate.MaxValue)
                {
                    return(DateTime.SpecifyKind(rawDateTime, DateTimeKind.Local));
                }

                var currentTimeZone = TimeZoneInfo.Local;

                return(TimeZoneInfo.ConvertTime(DateTime.SpecifyKind(rawDateTime, DateTimeKind.Unspecified), sourceTimeZone: account.SchoolTimeZone, destinationTimeZone: currentTimeZone));
            }
            catch (Exception ex)
            {
                TelemetryExtension.Current?.TrackException(new Exception("Invalid date: " + rawDateTime.ToString(), ex));

                return(DateTime.SpecifyKind(rawDateTime, DateTimeKind.Local));
            }
        }
Пример #9
0
        public List <GetDetalheAssistencia> ObterAssistenciasPorCongregacao(int congregacaoId, DateTime dataInicial, DateTime dataFinal)
        {
            using (RepositorySession dalSession = new RepositorySession(Runtime.JWInstance))
            {
                IUnitOfWork unitOfWork = dalSession.UnitOfWork;
                try
                {
                    var ret = _repository.ObterAssistenciasPorCongregacao(ref unitOfWork, congregacaoId, dataInicial, dataFinal);

                    for (int i = 0; i < ret.Count; i++)
                    {
                        ret[i].DiaSemana = DateValues.ObterDiaSemanaPortugues(ret[i].Data.DayOfWeek);
                    }

                    return(ret);
                }
                catch
                {
                    throw;
                }
            }
        }
        public DateTime GetLocalStartDateAndTime(AccountDataItem account, DataItemSemester semester, DataItemClass c)
        {
            DateTime startDate;

            if (!DateValues.IsUnassigned(semester.Start))
            {
                startDate = DateHelpers.ToViewItemTime(account, semester.Start);
            }
            else
            {
                startDate = DateTime.Today.AddYears(-1);
            }

            // If the class has a start date, we use that rather than the semester start date
            if (!DateValues.IsUnassigned(c.StartDate))
            {
                startDate = DateHelpers.ToViewItemTime(account, c.StartDate);
            }

            var currentWeek = account.GetWeekOnDifferentDate(startDate);

            // If the schedule doesn't occur each week
            if (this.ScheduleWeek != Schedule.Week.BothWeeks)
            {
                // If it's on the wrong week, we'll move it forward 7 days
                if (currentWeek != this.ScheduleWeek)
                {
                    startDate = startDate.AddDays(7);
                }
            }

            // Get the date the schedule actually starts on
            startDate = DateTools.Next(this.DayOfWeek, startDate);

            return(startDate.Add(this.StartTime.TimeOfDay));
        }