Esempio n. 1
0
        public async Task <Evaluation> Update(Evaluation evaluation, int pages)
        {
            var profileId = evaluation.Profile.Id;
            var chapterId = evaluation.Submit.ChapterId;
            var pageIndex = evaluation.Submit.PageIndex;

            var stats =
                await _database.QueryStats(chapterId, profileId) ??
                await _stats.Add(DbStats.Create(profileId, chapterId, pages));

            if (evaluation.Result == Result.Correct)
            {
                var completedBefore = stats.Completed;

                stats = stats
                        .WithSubmit(pageIndex)
                        .WithUpdatedCompleted();

                await _stats.Replace(stats);

                if (completedBefore != stats.Completed)
                {
                    await UpdateProfile(evaluation.Profile);
                }
            }
            else
            {
                await _stats.Replace(stats.WithFailure(pageIndex));
            }

            return(evaluation);
        }
Esempio n. 2
0
        private async Task <Stats> LoadStats(Guid chapterId, Guid profileId, int pages)
        {
            var stats =
                await _database.QueryStats(chapterId, profileId) ??
                await _stats.Add(DbStats.Create(profileId, chapterId, pages));

            return(_convertStats.Convert(stats));
        }
Esempio n. 3
0
        public void TEST_no_caching()
        {
            var DatabaseService = new DatabaseService(null, "TestDB" + Guid.NewGuid().ToString(), null, null, null);

            DatabaseService.DataBaseSettings.MaxResponseTime = TimeSpan.FromMinutes(5);
            for (int i = 0; i < 100; i++)
            {
                StorageDatabase <Finance <object>, object> fin     = DatabaseService.Documents <Finance <object>, object>();
                StorageDatabase <History <object>, object> History = DatabaseService.Documents <History <object>, object>();

                fin.LoadAll(true).ToList().ForEach(
                    x =>
                {
                    fin.Delete(x.Id);
                    fin.DeleteForever(x.Id);
                });
                History.LoadAll(true).ToList().ForEach(
                    x =>
                {
                    History.Delete(x.Id);
                    History.DeleteForever(x.Id);
                });
                IEnumerable <Finance <object> > allx = fin.LoadAll(true);
                Finance <object> data = fin.Create(new Finance <object>());
                IEnumerable <Finance <object> > allk     = fin.LoadAll(true);
                IEnumerable <Finance <object> > allhhjjw = fin.LoadAll(true);
                data.FileContent = "bla";
                IEnumerable <Finance <object> > allhhw = fin.LoadAll(true);
                fin.Update(data);
                IEnumerable <Finance <object> > allw = fin.LoadAll(true);
                History <object> h = History.Load(History.LoadAll(true).LastOrDefault().Id);
                data = fin.Load(data.Id);
                IEnumerable <Finance <object> > ally = fin.LoadAll(true);
                TestHelperMethods.AssertAwait(
                    () =>
                {
                    IEnumerable <Finance <object> > all = fin.LoadAll(true);
                    Assert.AreEqual(1, all.Count());
                });
                fin.Delete(data.Id);
                h = History.Load(History.LoadAll(true).Last().Id);
                DbStats stats = SystemDbService.GetSystemStatistics(DatabaseService, x => x.DocumentName != typeof(History <object>).Name);

                fin.DeleteForever(data.Id);
                h     = History.Load(History.LoadAll(true).LastOrDefault().Id);
                stats = SystemDbService.GetSystemStatistics(DatabaseService, x => x.DocumentName != typeof(History <object>).Name);

                TestHelperMethods.AssertAwait(() => Assert.AreEqual(0, fin.LoadAll(true).Count()));
            }
        }
Esempio n. 4
0
        public async Task <ContentResult> GetStats()
        {
            ContentResult response;
            DateTime      requestTimestamp = DateTime.UtcNow;

            if (!_context.Database.CanConnect())   // Проверка на доступность дб
            {
                response = Content("No connection to database.");
            }
            else
            {
                List <Car>         carsList = _context.Cars.ToList();
                List <LogMetadata> logs     = _context.Logs.ToList();

                if (carsList.Count + logs.Count != 0)   // Проверка на наличие записей во всех таблицах

                // <алгоритм нахождения самой ранней и самой поздней записей>
                // он не масштабируется, обусловлено это наличием лишь двух рабочих таблиц,
                // #YAGNI
                {
                    DateTime earliestRecordDate = logs[0].CreatedDate;
                    DateTime latestRecordDate   = logs[logs.Count - 1].CreatedDate;

                    if (DateTime.Compare(carsList[0].CreatedDate, logs[0].CreatedDate) < 0)
                    {
                        earliestRecordDate = carsList[0].CreatedDate;
                    }
                    if (DateTime.Compare(carsList[carsList.Count - 1].CreatedDate, logs[logs.Count - 1].CreatedDate) > 0)
                    {
                        latestRecordDate = carsList[carsList.Count - 1].CreatedDate;
                    }
                    // </алгоритм нахождения самой ранней и самой поздней записей>

                    DbStats stats = new DbStats(earliestRecordDate, latestRecordDate, carsList.Count + logs.Count);
                    response = Content(JsonSerializer.Serialize(stats));
                }
                else
                {
                    response = Content("No statistics.");
                }
            }

            // логирование
            await Logger.LogData(_context, Request, requestTimestamp, response);

            return(response);
        }
Esempio n. 5
0
        /// <summary>
        /// return total amount of sales for a game
        /// </summary>
        /// <param name="id">id of game</param>
        /// <returns>sales object with all the game's sales and purchases</returns>
        public static Sales SalesForGame(int id)
        {
            DataRow row = DbStats.getGameStats(id);

            if (row == null)
            {
                return new Sales
                       {
                           Purchases = 0,
                           Revenue   = 0
                       }
            }
            ;
            return(new Sales
            {
                Purchases = (int)row["Purchases"],
                Revenue = (double)row["Revenue"]
            });
        }
Esempio n. 6
0
        public void TestMethod1()
        {
            var DatabaseService = new DatabaseService(null, "TestDB" + Guid.NewGuid().ToString(), null, null, null);
            StorageDatabase <Finance <object>, object> fin     = DatabaseService.Documents <Finance <object>, object>();
            StorageDatabase <History <object>, object> History = DatabaseService.Documents <History <object>, object>();

            IEnumerable <History <object> > h = History.LoadAll(true);

            IEnumerable <Finance <object> > f = fin.LoadAll(true);
            Finance <object> mod = fin.Create(
                new Finance <object>
            {
                FileName = "shdlkhslkdhlksd"
            });

            h = History.LoadAll(true);

            IEnumerable <Finance <object> > f1 = fin.LoadAll();
            DbStats t = SystemDbService.GetSystemStatistics(DatabaseService);
            DbStats q = SystemDbService.GetSystemStatistics(DatabaseService, x => x.LastOperation == "CREATE");

            foreach (Finance <object> id in f1)
            {
                Finance <object> d = fin.Load(id.Id);
                fin.Delete(id.Id);
                fin.DeleteForever(id.Id);
            }
            h = History.LoadAll(true);
            f = fin.LoadAll(true);

            IEnumerable <History <object> > h1 = History.LoadAll();

            foreach (History <object> id in h1)
            {
                History <object> d = History.Load(id.Id);
                History.Delete(id.Id);
                History.DeleteForever(id.Id);
            }
            h = History.LoadAll(true);
            f = fin.LoadAll(true);
            t = SystemDbService.GetSystemStatistics(DatabaseService);
        }
        public async Task Update(Profile profile, Guid chapterId, int pageIndex)
        {
            var stats = await _database.QueryStats(chapterId, profile.Id);

            if (stats == default)
            {
                var chapter = await _chapters.Get(chapterId);

                if (chapter != null)
                {
                    var pages = chapter.Pages?.Length ?? 0;
                    stats = await _stats.Add(DbStats.Create(profile.Id, chapter.Id, pages));
                }
                else
                {
                    throw new ObjectNotFoundException(typeof(DbChapter), chapterId);
                }
            }

            await _stats.Replace(stats.WithTip(pageIndex));
        }
Esempio n. 8
0
        public void TEST_with_caching_inmemory()
        {
            var DatabaseService = new DatabaseService(null, "TestDB" + Guid.NewGuid().ToString(), null, null, null);

            for (int i = 0; i < 100; i++)
            {
                DatabaseService.DataBaseSettings.EnableFasterCachingButWithLeakyUpdates = true;
                StorageDatabase <Finance <object>, object> fin     = DatabaseService.Documents <Finance <object>, object>();
                StorageDatabase <History <object>, object> History = DatabaseService.Documents <History <object>, object>();

                fin.LoadAll(true).ToList().ForEach(
                    x =>
                {
                    fin.Delete(x.Id);
                    fin.DeleteForever(x.Id);
                });
                History.LoadAll(true).ToList().ForEach(
                    x =>
                {
                    History.Delete(x.Id);
                    History.DeleteForever(x.Id);
                });

                Finance <object> data = fin.Create(new Finance <object>());
                data.FileContent = "bla";
                fin.Update(data);
                History <object> h = History.Load(History.LoadAll(true).LastOrDefault().Id);
                data = fin.Load(data.Id);
                TestHelperMethods.AssertAwait(() => Assert.AreEqual(1, fin.LoadAll(true).Count()));
                fin.Delete(data.Id);
                h = History.Load(History.LoadAll(true).Last().Id);
                DbStats stats = SystemDbService.GetSystemStatistics(DatabaseService, x => x.DocumentName != typeof(History <object>).Name);

                fin.DeleteForever(data.Id);
                h     = History.Load(History.LoadAll(true).LastOrDefault().Id);
                stats = SystemDbService.GetSystemStatistics(DatabaseService, x => x.DocumentName != typeof(History <object>).Name);

                TestHelperMethods.AssertAwait(() => Assert.AreEqual(0, fin.LoadAll(true).Count()));
            }
        }
Esempio n. 9
0
 /// <summary>
 /// returns a list of sale days for all games
 /// </summary>
 /// <returns>list of sales</returns>
 public static List <Sales> AllStats()
 {
     return(DataTableToList(DbStats.TotalSalesStats()));
 }
Esempio n. 10
0
 /// <summary>
 /// returns a list of sale days for all games from a developer
 /// </summary>
 /// <param name="devId">id of developer</param>
 /// <returns>list of sales</returns>
 public static List <Sales> CompanyStats(int devId)
 {
     return(DataTableToList(DbStats.CompanySalesStats(devId)));
 }
Esempio n. 11
0
 /// <summary>
 /// returns a list of sale days for a game
 /// </summary>
 /// <param name="gameId">id of game</param>
 /// <returns>list of sales</returns>
 public static List <Sales> GameStats(int gameId)
 {
     return(DataTableToList(DbStats.GameSalesStats(gameId)));
 }
Esempio n. 12
0
        public static DbBreakpoint GenBreakpoint(DSPlayer pl, int bp, string bpstring)
        {
            DbBreakpoint Bp = new DbBreakpoint();

            Bp.Player = pl;
            Bp.Gas    = pl.Refineries.Where(x => x.Gameloop > 0 && x.Gameloop <= bp).Count();
            Bp.Income = (int)pl.Stats.Where(x => x.Gameloop <= bp).Sum(s => s.MineralsCollectionRate / 9.15);
            DbStats statlast = null;

            foreach (DbStats stat in pl.Stats)
            {
                if (stat.Gameloop > bp)
                {
                    break;
                }
                statlast = stat;
            }
            if (statlast != null)
            {
                Bp.Army     = statlast.Army;
                Bp.Kills    = statlast.MineralsKilledArmy;
                Bp.Upgrades = statlast.MineralsUsedCurrentTechnology;
            }

            List <DbUnit> dbUnits = null;

            foreach (var ent in pl.Spawns)
            {
                if (ent.Gameloop > bp)
                {
                    break;
                }
                dbUnits = ent.Units.ToList();
            }
            Bp.Units   = new List <DSUnit>();
            Bp.DbUnits = new List <DbUnit>();
            if (dbUnits != null)
            {
                foreach (DbUnit unit in dbUnits)
                {
                    DSUnit dsUnit = Bp.Units.FirstOrDefault(s => s.Name == unit.Name);
                    if (dsUnit == null)
                    {
                        DSUnit newdsUnit = new DSUnit();
                        newdsUnit.Name       = unit.Name;
                        newdsUnit.BP         = bpstring;
                        newdsUnit.Breakpoint = Bp;
                        newdsUnit.Count      = 1;
                        newdsUnit.DSPlayer   = pl;
                        Bp.Units.Add(newdsUnit);
                    }
                    else
                    {
                        dsUnit.Count++;
                    }
                    unit.Breakpoint = Bp;
                    Bp.DbUnits.Add(unit);
                }
            }

            Bp.DbUpgrades = new List <DbUpgrade>();
            foreach (DbUpgrade upgrade in pl.Upgrades.Where(x => x.Breakpoint == null && x.Gameloop < bp))
            {
                upgrade.Breakpoint = Bp;
                Bp.DbUpgrades.Add(upgrade);
            }

            string dsUnitsString    = "";
            string dbUnitsString    = "";
            string dbUpgradesString = "";

            foreach (DSUnit unit in Bp.Units)
            {
                string        name  = unit.Name;
                UnitModelBase bunit = DSdata.Units.FirstOrDefault(s => s.Race == pl.RACE && s.Name == unit.Name);
                if (bunit != null)
                {
                    name = bunit.ID.ToString();
                }
                dsUnitsString += name + "," + unit.Count + "|";
            }
            if (dsUnitsString.Any())
            {
                dsUnitsString = dsUnitsString.Remove(dsUnitsString.Length - 1);
            }

            foreach (DbUnit unit in Bp.DbUnits)
            {
                string        name  = unit.Name;
                UnitModelBase bunit = DSdata.Units.FirstOrDefault(s => s.Race == pl.RACE && s.Name == unit.Name);
                if (bunit != null)
                {
                    name = bunit.ID.ToString();
                }
                dbUnitsString += name + "," + unit.BornX + "," + unit.BornY + "|";
            }
            if (dbUnitsString.Any())
            {
                dbUnitsString = dbUnitsString.Remove(dbUnitsString.Length - 1);
            }


            foreach (DbUpgrade upgrade in Bp.DbUpgrades)
            {
                dbUpgradesString += upgrade.Upgrade + "|";
            }
            if (dbUpgradesString.Any())
            {
                dbUpgradesString = dbUpgradesString.Remove(dbUpgradesString.Length - 1);
            }

            Bp.dsUnitsString    = dsUnitsString;
            Bp.dbUnitsString    = dbUnitsString;
            Bp.dbUpgradesString = dbUpgradesString;

            return(Bp);
        }
Esempio n. 13
0
        public static DbBreakpoint GenBreakpoint(DSPlayer pl, int bp, string bpstring)
        {
            DbBreakpoint Bp = new DbBreakpoint();

            Bp.Player = pl;
            Bp.Gas    = pl.Refineries.Where(x => x.Gameloop > 0 && x.Gameloop <= bp).Count();
            Bp.Income = (int)pl.Stats.Where(x => x.Gameloop <= bp).Sum(s => s.MineralsCollectionRate / 9.15);
            DbStats statlast = pl.Stats.Where(x => x.Gameloop <= bp).LastOrDefault();

            if (statlast != null)
            {
                Bp.Army     = statlast.Army;
                Bp.Kills    = statlast.MineralsKilledArmy;
                Bp.Upgrades = statlast.MineralsUsedCurrentTechnology;
            }

            List <DbUnit> dbUnits   = null;
            var           spawnlast = pl.Spawns.Where(x => x.Gameloop <= bp).LastOrDefault();

            if (spawnlast != null)
            {
                dbUnits = spawnlast.Units.ToList();
            }

            Bp.Units   = new List <DSUnit>();
            Bp.DbUnits = new List <DbUnit>();
            if (dbUnits != null)
            {
                foreach (DbUnit unit in dbUnits)
                {
                    DSUnit dsUnit = Bp.Units.FirstOrDefault(s => s.Name == unit.Name);
                    if (dsUnit == null)
                    {
                        Bp.Units.Add(new DSUnit()
                        {
                            Name       = unit.Name,
                            BP         = bpstring,
                            Breakpoint = Bp,
                            Count      = 1,
                            DSPlayer   = pl
                        });
                    }
                    else
                    {
                        dsUnit.Count++;
                    }
                    unit.Breakpoint = Bp;
                    Bp.DbUnits.Add(unit);
                }
            }

            Bp.DbUpgrades = new List <DbUpgrade>();
            foreach (DbUpgrade upgrade in pl.Upgrades.Where(x => x.Breakpoint == null && x.Gameloop < bp))
            {
                upgrade.Breakpoint = Bp;
                Bp.DbUpgrades.Add(upgrade);
            }

            string dsUnitsString    = "";
            string dbUnitsString    = "";
            string dbUpgradesString = "";

            foreach (DSUnit unit in Bp.Units)
            {
                string name = unit.Name;
                int    id   = NameService.GetUnitId(null, unit.Name);
                if (id >= 0)
                {
                    name = id.ToString();
                }
                dsUnitsString += name + "," + unit.Count + "|";
            }
            if (dsUnitsString.Any())
            {
                dsUnitsString = dsUnitsString.Remove(dsUnitsString.Length - 1);
            }

            foreach (DbUnit unit in Bp.DbUnits)
            {
                string name = unit.Name;
                int    id   = NameService.GetUnitId(null, unit.Name);
                if (id >= 0)
                {
                    name = id.ToString();
                }
                dbUnitsString += name + "," + unit.BornX + "," + unit.BornY + "|";
            }
            if (dbUnitsString.Any())
            {
                dbUnitsString = dbUnitsString.Remove(dbUnitsString.Length - 1);
            }


            foreach (DbUpgrade upgrade in Bp.DbUpgrades)
            {
                dbUpgradesString += upgrade.Upgrade + "|";
            }
            if (dbUpgradesString.Any())
            {
                dbUpgradesString = dbUpgradesString.Remove(dbUpgradesString.Length - 1);
            }

            Bp.dsUnitsString    = dsUnitsString;
            Bp.dbUnitsString    = dbUnitsString;
            Bp.dbUpgradesString = dbUpgradesString;

            return(Bp);
        }