public void TestConversion()
        {
            DateTime dt = new DateTime(2013, 1, 16, 14, 20, 0);
            long ts = dt.ToTimestamp();

            Assert.AreEqual(ts, 1358346000000);

            DateTime cdt = ts.ToDateTime();
            Assert.AreEqual(cdt, dt);
        }
        public void Convert_correctly_converts_RequestDate()
        {
            // arrange
            var requestDate = new DateTime(2011, 2, 3, 15, 3, 21);
            var ts = requestDate.ToTimestamp();
            var request = new PortfolioCalculationRequest { RequestTimestamp = ts  };
            var provider = new PortfolioCalculationRequestProvider();

            // act
            var model = provider.Convert(request);

            // assert
            Assert.That(model.RequestTimestamp, Is.EqualTo(ts));
        }
Example #3
0
        public async Task<List<dynamic>> GetPhotoPostsAsync(string tag, DateTime before, int limit)
        {
            var timestamp = before.ToTimestamp();
            var q = $"tag={tag}&before={timestamp}&limit={limit}&api_key={_apiKey}";

            string url = $"{BaseUrl}/tagged?{q}";
            var posts = await _httpClient.GetAsync(url);

            return ((IEnumerable<dynamic>) posts.response)
                .Where(p => p.type == "photo" &&
                            DynamicHelper.HasProperty(() => p.image_permalink) &&
                            (p.image_permalink != null && p.image_permalink.ToString() != string.Empty))
                .ToList();
        }
Example #4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <returns></returns>
        public IQueryable<Market> GetInterval(DateTime @from, DateTime to)
        {
            var filename = PathResolver.GetFilename(to);

            return LoadData(line =>
            {
                var date = Parser.ParseDate(line);
                if (date <= to.ToTimestamp() && date >= from.ToTimestamp())
                {
                    return Parser.ParseRecord(line);
                }
                return null;
            }, filename).AsQueryable();
        }
        public void xxx_test()
        {
            var x = new DateTime(1970, 1, 1, 0, 0, 0, 0);
            var now = DateTime.Now;

            //long timestamp = 1380483372;
            const long timestamp = 0;
            Console.WriteLine(x);

            Console.WriteLine(x.ToTimestamp());
            Console.WriteLine("xx");
            Console.WriteLine(x.ToUniversalTime().ToTimestamp());
            Console.WriteLine(timestamp.ToDateTime().ToLocalTime());
            Console.WriteLine(timestamp.ToDateTime());
        }
        public void ConvertToPortfolioFileInfo_sets_UploadTimestamp_from_current_time()
        {
            // arrange
            var dt = new DateTime(2011, 4, 1, 9, 33, 21);
            var ts = dt.ToTimestamp();
            SystemTime.Now = () => dt;
            var putInfo = new S3PutInfo();
            var provider = new PortfolioCalculationRequestProvider();

            // act

            var actual = provider.ConvertToPortfolioFileInfo(putInfo);

            // assert
            Assert.That(actual.UploadTimestamp, Is.EqualTo(ts));
        }
        public void SavePortfolioFile_calls_correct_methods()
        {
            // arrange
            var dt = new DateTime(2011, 4, 1, 9, 33, 21);
            SystemTime.Now = () => dt;
            var savePath = "foobarbat";
            var clientFileName = "zeezing";

            var putInfo = MockRepository.GenerateMock<S3PutInfo>();
            var fileInfo = MockRepository.GenerateMock<PortfolioFileInfo>();
            fileInfo.Expect(f => f.UploadTimestamp).Return(dt.ToTimestamp());

            var s3Client = MockRepository.GenerateStub<S3Client>(null, null);
            s3Client.Expect(s => s.Save(null, null, null)).IgnoreArguments().Return(putInfo);

            var model = MockRepository.GenerateStub<PortfolioCalculationRequestInputModel>();
            model.Expect(m=>m.ClientFileName).Return(clientFileName);

            var provider = MockRepository.GenerateMock<PortfolioCalculationRequestProvider>();
            provider.Expect(p => p.S3Client).Return(s3Client);
            provider.Expect(p => p.CalculatePortfolioFileSavePath(model)).Return(savePath);
            provider.Expect(p => p.ConvertToPortfolioFileInfo(putInfo)).Return(fileInfo);
            provider.Expect(p => p.SavePortfolioFile(model)).CallOriginalMethod(OriginalCallOptions.CreateExpectation);

            // act
            provider.SavePortfolioFile(model);

            // assert
            s3Client.VerifyAllExpectations();
            model.VerifyAllExpectations();
            provider.VerifyAllExpectations();
        }
Example #8
0
        IEnumerable<Flot> GetFlotData(DateTime aStart, DateTime aEnd)
        {
            var tObjects = new List<Flot>();

            FetchData data = Helper.RrdDb.createFetchRequest(ConsolFuns.CF_AVERAGE, aStart.ToTimestamp(), aEnd.ToTimestamp(), 1).fetchData();
            Int64[] times = data.getTimestamps();
            double[][] values = data.getValues();

            for (int a = 1; a <= Snapshot.SnapshotCount; a++)
            {
                var obj = new Flot();

                var list = new List<double[]>();
                for (int b = 0; b < times.Length; b++)
                {
                    double[] current = { times[b] * 1000, values[a][b] };
                    list.Add(current);
                }
                obj.Data = list.ToArray();
                obj.Type = a;

                tObjects.Add(obj);
            }

            return tObjects.ToArray();
        }