Ejemplo n.º 1
0
        public async Task CreateCsv(CsvRequest request)
        {
            int totalDays = (int)(request.EndDate - request.StartDate).TotalDays + 1;

            Logger.Info("Creating CSV for {0} days, using {1} fields, Saving to {2}", totalDays, request.Features.Count, request.FilePath);

            int     rowCount = 0;
            JObject o        = null;

            for (int i = 0; i < totalDays; i++)
            {
                o = await Snapshot.GetDetailedSnapshot(request.StartDate.AddDays(i));

                foreach (var game in o["Games"] as JArray)
                {
                    bool success = AddGameToCsv(game, request.FilePath, request.Features, request.Target);
                    if (success)
                    {
                        rowCount++;
                    }
                }

                Logger.Info("Completed CSV stream {0} of {1} ({2} rows)", (i + 1), totalDays, rowCount);
            }
            Logger.Info("Completed CSV stream from {0} to {1} ({2} days)", request.StartDate.ToShortDateString(), request.EndDate.ToShortDateString(), totalDays);
        }
Ejemplo n.º 2
0
        public async Task <List <object> > CreateCSVForScorboard(CsvRequest req)
        {
            var results  = new List <object>();
            var snapshot = await Snapshot.GetDetailedSnapshot(req.StartDate);

            if (!req.RequireTarget)
            {
                req.Target = null;
            }

            foreach (var game in snapshot["Games"] as JArray)
            {
                if (isGameValid(game, req))
                {
                    string csv = CreateCSVRow(game, req.Features, req.Target);
                    results.Add(new
                    {
                        Date    = game["Date"].Value <string>(),
                        Summary = CreateGameSummary(game),
                        Home    = game.SelectToken("Home.Team"),
                        Away    = game.SelectToken("Away.Team"),
                        DataRow = csv
                    });
                }
            }
            return(results);
        }
        protected override void configureRequest(CsvRequest <TestCsvObject> request)
        {
            request.HeadersExist      = true;
            request.UseHeaderOrdering = true;

            request.Delimiter = '|';
        }
Ejemplo n.º 4
0
        private bool isGameValid(JToken game, CsvRequest req)
        {
            string gameType = game.SafeParseToken <string>("Type", Logger);

            if (!req.RequiredGameTypes.Contains(gameType))
            {
                Logger.Info("Game type {0} is not in the allowed list of game types, discarding", gameType);
            }
            string gameStatus = game.SafeParseToken <string>("Status", Logger);

            if (!req.RequiredGameStatus.Contains(gameStatus))
            {
                Logger.Info("Game status {0} is not in the allowed list of game status', discarding", gameStatus);
            }
            string awayLeague = game.SafeParseToken <string>("Away.Team.League", Logger);

            if (!req.RequiredTeamLeagues.Contains(awayLeague))
            {
                Logger.Info("Away Team League {0} is not in the allowed list of team leagues, discarding", awayLeague);
            }
            string homeLeague = game.SafeParseToken <string>("Home.Team.League", Logger);

            if (!req.RequiredTeamLeagues.Contains(homeLeague))
            {
                Logger.Info("Home Team League {0} is not in the allowed list of team leaguees, discarding", homeLeague);
            }
            return(true);
        }
Ejemplo n.º 5
0
        public void SetUp()
        {
            theFile = "{0}.csv".ToFormat(GetType().Name);

            beforeEach();

            using (var writer = new StreamWriter(theFile))
            {
                writeFile(writer);
            }

            theReader = new CsvReader(ObjectResolver.Basic());

            theResults = new List <T>();

            theRequest = new CsvRequest <T>
            {
                Mapping  = new TMap(),
                FileName = theFile,
                Callback = theResults.Add
            };

            configureRequest(theRequest);

            theReader.Read(theRequest);
        }
Ejemplo n.º 6
0
        private void Load(Stream stream)
        {
            _list.Clear();

            var request = new CsvRequest <T>
            {
                HeadersExist      = false,
                UseHeaderOrdering = false,
                OpenStream        = () => stream,
                Mapping           = new TMap(),
                Callback          = (obj) => _list.Add(obj)
            };

            var reader = new CsvReader(ObjectResolver.Basic());

            reader.Read(request);
        }
Ejemplo n.º 7
0
 protected override void configureRequest(CsvRequest <TestCsvObject> request)
 {
     request.HeadersExist = false;
 }
Ejemplo n.º 8
0
 protected override void configureRequest(CsvRequest <TestCsvObject> request)
 {
     base.configureRequest(request);
     request.Mapping.As <TestCsvDescriptionMapping>().Alias(getExpectedContent());
 }
Ejemplo n.º 9
0
 public void SetUp()
 {
     theRequest = new CsvRequest<TestCsvObject>();
 }
Ejemplo n.º 10
0
 protected virtual void configureRequest(CsvRequest <T> request)
 {
 }
Ejemplo n.º 11
0
 public void SetUp()
 {
     theRequest = new CsvRequest <TestCsvObject>();
 }