Ejemplo n.º 1
0
 private static Indicator CreateIndicator(IDictionary <string, string> properties, IDictionary <string, PropertyDescription> descriptions)
 {
     return(Indicator.Create(
                ticker,
                properties is null ? PropertyDictionary.Empty() : new PropertyDictionary(properties),
                descriptions is null ? PropertyDescriptionDictionary.Empty() : new PropertyDescriptionDictionary(descriptions)
                ));
 }
Ejemplo n.º 2
0
 private static Quarter CreateQuarter(string ticker, FiscalQuarterPeriod period, IDictionary <string, string> properties, IDictionary <string, PropertyDescription> descriptions)
 {
     return(Quarter.Create(
                ticker,
                period,
                properties is null ? PropertyDictionary.Empty() : new PropertyDictionary(properties),
                descriptions is null ? PropertyDescriptionDictionary.Empty() : new PropertyDescriptionDictionary(descriptions)
                ));
 }
 private static Daily CreateDaily(string ticker, DayPeriod period, IDictionary <string, string> properties, IDictionary <string, PropertyDescription> descriptions)
 {
     return(Daily.Create(
                ticker,
                period,
                properties is null ? PropertyDictionary.Empty() : new PropertyDictionary(properties),
                descriptions is null ? PropertyDescriptionDictionary.Empty() : new PropertyDescriptionDictionary(descriptions)
                ));
 }
Ejemplo n.º 4
0
        public void GetHashCodeTest()
        {
            var a = new PropertyDescriptionDictionary(descriptions).GetHashCode();
            var b = new PropertyDescriptionDictionary(descriptions).GetHashCode();
            var c = PropertyDescriptionDictionary.Empty().GetHashCode();

            Assert.AreEqual(a, b);
            Assert.AreNotEqual(a, c);
        }
        private static Daily ParseDaily(PropertyDictionary properties, PropertyDescriptionDictionary descriptions)
        {
            var period = DayPeriod.Parse(properties.Get(PropertyNames.Day));

            return(Daily.Create(
                       properties.Get(PropertyNames.Ticker),
                       period,
                       properties,
                       descriptions
                       ));
        }
        private static Quarter ParseQuarter(
            PropertyDictionary properties,
            PropertyDescriptionDictionary descriptions)
        {
            var fiscalYear    = Convert.ToUInt16(properties.Get(PropertyNames.FiscalYear));
            var fiscalQuarter = Convert.ToUInt16(properties.Get(PropertyNames.FiscalQuarter));

            return(Quarter.Create(
                       properties.Get(PropertyNames.Ticker),
                       fiscalYear,
                       fiscalQuarter,
                       properties,
                       descriptions
                       ));
        }
 public static PropertyDescriptionDictionary Parse(IList <JToken> columnDescription)
 {
     if (columnDescription.Count > 0)
     {
         try
         {
             var dict = columnDescription.First().SelectMany(t => t.Children()).Where(t => t is JProperty).Cast <JProperty>().Where(_ => !PropertyNames.IgnoredPropertyNames.Contains(_.Name)).Select(t => ToPropertyDescription(t)).ToDictionary(p => p.Name, p => p);
             return(new PropertyDescriptionDictionary(dict));
         }
         catch (Exception e)
         {
             throw new ApiResponseParserException("parse column definitions failed", e);
         }
     }
     else
     {
         return(PropertyDescriptionDictionary.Empty());
     }
 }
        private static Company ParseCompany(
            PropertyDictionary properties,
            PropertyDescriptionDictionary descriptions)
        {
            var fixedTierRangeJson = JObject.Parse(properties.Get(PropertyNames.FixedTierRange));
            var fixedTierRange     = FixedTierRangeParser.Parse(fixedTierRangeJson.Properties());

            var oldestFy = uint.Parse(properties.Get(PropertyNames.OldestFiscalYear));
            var oldestFq = uint.Parse(properties.Get(PropertyNames.OldestFiscalQuarter));

            var latestFy   = uint.Parse(properties.Get(PropertyNames.LatestFiscalYear));
            var latestFq   = uint.Parse(properties.Get(PropertyNames.LatestFiscalQuarter));
            var oldestDate = DayPeriod.Parse(properties.Get(PropertyNames.OldestDate));
            // use today as latest date
            var latestDate = DayPeriod.Create(DateTime.Today);

            var fixedTierQuarterRange = PeriodRange <FiscalQuarterPeriod> .Create(fixedTierRange.OldestQuarter, fixedTierRange.LatestQuarter);

            var fixedTierDayRange = PeriodRange <DayPeriod> .Create(fixedTierRange.OldestDate, fixedTierRange.LatestDate);

            var ondemandPeriodRange = PeriodRange <FiscalQuarterPeriod> .Create(
                FiscalQuarterPeriod.Create(oldestFy, oldestFq),
                FiscalQuarterPeriod.Create(latestFy, latestFq)
                );

            var ondemandTierDayRange = PeriodRange <DayPeriod> .Create(oldestDate, latestDate);

            return(Company.Create(
                       properties.Get(PropertyNames.Ticker),
                       fixedTierQuarterRange,
                       ondemandPeriodRange,
                       fixedTierDayRange,
                       ondemandTierDayRange,
                       properties,
                       descriptions
                       ));
        }
        public void GetDayTest()
        {
            var company = Company.Create(ticker, fixedTierQuarterRange, ondemandTierQuarterRange, fixedTierDayRange, ondemandTierDayRange, PropertyDictionary.Empty(), PropertyDescriptionDictionary.Empty());

            var dict = new SupportedTierDictionary <DayPeriod>();

            // throw Key NotFound
            Assert.ThrowsException <KeyNotFoundException>(() => dict.Get(ticker, fixedTierLatestDay));

            // day
            Assert.AreEqual(SupportedTier.FixedTier, dict.Get(ticker, ondemandLatestDay));
            Assert.AreEqual(SupportedTier.FixedTier, dict.Get(ticker, fixedTierLatestDay));
            Assert.AreEqual(SupportedTier.FixedTier, dict.Get(ticker, fixedTierOldestDay));
            Assert.AreEqual(SupportedTier.FixedTier, dict.Get(ticker, (DayPeriod)fixedTierOldestDay.Next()));
            Assert.AreEqual(SupportedTier.OndemandTier, dict.Get(ticker, (DayPeriod)fixedTierOldestDay.Prev()));
            Assert.AreEqual(SupportedTier.OndemandTier, dict.Get(ticker, ondemandOldestDay));
            Assert.AreEqual(SupportedTier.OndemandTier, dict.Get(ticker, (DayPeriod)ondemandOldestDay.Next()));
            Assert.AreEqual(SupportedTier.None, dict.Get(ticker, (DayPeriod)ondemandOldestDay.Prev()));
            Assert.AreEqual(SupportedTier.None, dict.Get(ticker, (DayPeriod)fixedTierLatestDay.Next()));
            Assert.AreEqual(SupportedTier.None, dict.Get(ticker, (DayPeriod)ondemandLatestDay.Next()));
        }
        public void GetQuarterTest()
        {
            var company = Company.Create(ticker, fixedTierQuarterRange, ondemandTierQuarterRange, fixedTierDayRange, ondemandTierDayRange, PropertyDictionary.Empty(), PropertyDescriptionDictionary.Empty());

            var dict = new SupportedTierDictionary <FiscalQuarterPeriod>();

            // throw Key NotFound
            Assert.ThrowsException <KeyNotFoundException>(() => dict.Get(ticker, fixedLatestQuarter));

            dict.Add(company.Ticker, company.SupportedQuarterRanges);
            // quarter
            Assert.AreEqual(SupportedTier.FixedTier, dict.Get(ticker, fixedOldestQuarter));
            Assert.AreEqual(SupportedTier.FixedTier, dict.Get(ticker, (FiscalQuarterPeriod)fixedOldestQuarter.Next()));
            Assert.AreEqual(SupportedTier.FixedTier, dict.Get(ticker, fixedLatestQuarter));
            Assert.AreEqual(SupportedTier.OndemandTier, dict.Get(ticker, ondemandOldestQuarter));
            Assert.AreEqual(SupportedTier.OndemandTier, dict.Get(ticker, (FiscalQuarterPeriod)ondemandOldestQuarter.Next()));
            Assert.AreEqual(SupportedTier.OndemandTier, dict.Get(ticker, ondemandLatestQuarter));
            Assert.AreEqual(SupportedTier.None, dict.Get(ticker, (FiscalQuarterPeriod)ondemandLatestQuarter.Next()));
        }
        public void AddAndHasTest()
        {
            var dict    = new SupportedTierDictionary <FiscalQuarterPeriod>();
            var company = Company.Create(ticker, fixedTierQuarterRange, ondemandTierQuarterRange, fixedTierDayRange, ondemandTierDayRange, PropertyDictionary.Empty(), PropertyDescriptionDictionary.Empty());

            // at first, not contained
            Assert.IsFalse(dict.Has(ticker));
            dict.Add(company.Ticker, company.SupportedQuarterRanges);
            // check added
            Assert.IsTrue(dict.Has(ticker));
        }
Ejemplo n.º 12
0
        public void GetTest()
        {
            var container = new PropertyDescriptionDictionary(descriptions);

            Assert.AreEqual(description, container.Get("key"));
        }
Ejemplo n.º 13
0
        public void EmptyTest()
        {
            var empty = PropertyDescriptionDictionary.Empty();

            Assert.AreEqual(0, empty.Count);
        }