Esempio n. 1
0
        public async Task <HandleResult> Edit([FromBody] ModelTable model)
        {
            var info = model.Id > 0 ? await _service.GetById(model.Id) : new ModelTable();

            if (info == null)
            {
                return(HandleResult.Error("无效数据"));
            }

            bool isUpdate = info.Id > 0;

            if (!isUpdate)
            {
                var verify = await _service.GetByTableName(model.TableName);

                if (verify != null && verify.Id != info.Id)
                {
                    return(HandleResult.Error("表名已存在"));
                }
            }

            info.Init();
            ReactForm.SetEditModelValue(info, model, isUpdate);

            var res = isUpdate
                ? await _service.Update(info)
                : await _service.Add(info);

            if (res.IsSuccess && !isUpdate)
            {
                _service.CreateTable(info);
            }

            return(res);
        }
Esempio n. 2
0
    public override void Reduce(Event evt, ModelTable table)
    {
        Type type = evt.GetType();

        if (type == typeof(NewGameBegun))
        {
            NewGameBegun gameBegun = (NewGameBegun)evt;
            table.InsertModel(gameBegun.playerId, new PlayerReadModel(gameBegun.playerId, gameBegun.playerName));
            return;
        }
    }
Esempio n. 3
0
        private async Task <IActionResult> RenderInfo(Site site, Column column, ModelTable model)
        {
            ContentData item = null;

            if (model != null)
            {
                item = await _contentService.GetFirstByColumnNum(model.SqlTableName, column.Num);
            }

            return(await RenderInfo(site, column, model, item));
        }
Esempio n. 4
0
 /// <summary>
 /// Extracts the state from the garden model at the given position.
 /// </summary>
 /// <param name="gardenModel">The garden model.</param>
 /// <param name="position">The position.</param>
 /// <returns>The extracted state.</returns>
 public static State ExtractStateFromGardenModelAtPosition(ModelTable gardenModel, Garden.GridPosition position)
 {
     return(new State(
                gardenModel.GardenModelAtPosition(position + MovementAction.North().GridMovement),
                gardenModel.GardenModelAtPosition(position + MovementAction.NorthEast().GridMovement),
                gardenModel.GardenModelAtPosition(position + MovementAction.East().GridMovement),
                gardenModel.GardenModelAtPosition(position + MovementAction.SouthEast().GridMovement),
                gardenModel.GardenModelAtPosition(position + MovementAction.South().GridMovement),
                gardenModel.GardenModelAtPosition(position + MovementAction.SouthWest().GridMovement),
                gardenModel.GardenModelAtPosition(position + MovementAction.West().GridMovement),
                gardenModel.GardenModelAtPosition(position + MovementAction.NorthWest().GridMovement),
                position
                ));
 }
Esempio n. 5
0
        public static ModelTable StrucItemToModelTable(List <AppStructItem> appStructItems)
        {
            var modelTable = new ModelTable();

            modelTable.TableInfoList = new List <TableInfo>();
            foreach (var item in appStructItems)
            {
                var tableInfo = new TableInfo();
                tableInfo.Name     = item.Name;
                tableInfo.PropName = item.Type;
                modelTable.TableInfoList.Add(tableInfo);
            }

            return(modelTable);
        }
Esempio n. 6
0
        public IEBIMModel(ModelTable paramModelTable, File paramFile)
        {
            ApplicationName = paramModelTable.ApplicationName;
            string str = removeExtension(paramFile.Name);

            Name         = str;
            ShortName    = str;
            DisplayName  = removeExtension(paramFile.Name);
            FileName     = paramFile.Name;
            Buildings    = new List <object>();
            Groups       = new List <object>();
            Sites        = new List <object>();
            Id           = Convert.ToInt64(DateTimeHelper.CurrentUnixTimeMillis() / 2L);
            this.offsetZ = (this.offsetY = (this.offsetX = (this.vertexConversionFactor = Convert.ToDouble((paramModelTable.VertexConversionFactor == null) ? 1.0D : paramModelTable.VertexConversionFactor.doubleValue())).valueOf((paramModelTable.OffsetX == null) ? 0.0D : paramModelTable.OffsetX.doubleValue())).valueOf((paramModelTable.OffsetY == null) ? 0.0D : paramModelTable.OffsetY.doubleValue())).valueOf((paramModelTable.OffsetZ == null) ? 0.0D : paramModelTable.OffsetZ.doubleValue());
        }
Esempio n. 7
0
 public BEBIMModel(ModelTable paramModelTable)
 {
     ApplicationName = paramModelTable.ApplicationName;
     DisplayName     = paramModelTable.Project.Code + " " + paramModelTable.Name;
     ShortName       = paramModelTable.Name;
     Name            = paramModelTable.Name;
     FileName        = Path.GetFileName(paramModelTable.FilePath);
     ModelId         = paramModelTable.Id;
     Revision        = paramModelTable.Revision;
     Groups          = new LinkedList();
     Sites           = new LinkedList();
     Buildings       = new LinkedList();
     Id           = paramModelTable.Id;
     this.offsetZ = (this.offsetY = (this.offsetX = (this.vertexConversionFactor = Convert.ToDouble((paramModelTable.VertexConversionFactor == null) ? 1.0D : paramModelTable.VertexConversionFactor.doubleValue())).valueOf((paramModelTable.OffsetX == null) ? 0.0D : paramModelTable.OffsetX.doubleValue())).valueOf((paramModelTable.OffsetY == null) ? 0.0D : paramModelTable.OffsetY.doubleValue())).valueOf((paramModelTable.OffsetZ == null) ? 0.0D : paramModelTable.OffsetZ.doubleValue());
 }
Esempio n. 8
0
        private async Task <IActionResult> RenderInfo(Site site, Column column, ModelTable model, ContentData item)
        {
            string folderName   = site.IsMobileSite ? site.MobileSiteFolder : site.SiteFolder;
            string templatePath = $"Views/Content/{folderName}/{column.InfoTemplatePath}";

            if (!System.IO.File.Exists(Path.GetFullPath(templatePath)))
            {
                return(Error404());
            }

            var seo  = new ContentSeo(column);
            var info = new ContentInfo();

            if (item != null)
            {
                int clickCount = item.ClickCount;
                int id         = item.Id;

                info.Column     = column;
                info.Site       = site;
                info.ModelTable = model;
                info.Data       = item;
                info.NextData   = await _contentService.GetNext(model.SqlTableName, column.Num, id);

                info.PrevData = await _contentService.GetPrev(model.SqlTableName, column.Num, id);

                seo.Title   = item.SeoTitle;
                seo.Keyword = item.SeoKeyword;
                seo.Desc    = item.SeoDesc;
                await _contentService.UpdateClickCount(model.SqlTableName, id, clickCount + 1);
            }

            ViewData.Model = info;
            ViewBag.Seo    = seo;
            ViewBag.Site   = site;
            return(View($"~/{templatePath}"));
        }
    public override void Reduce(Event evt, ModelTable table)
    {
        Type type = evt.GetType();

        if (type == typeof(CharacterCreated))
        {
            CharacterCreated characterCreated = (CharacterCreated)evt;
            table.InsertModel(characterCreated.name, new CharacterReadModel(characterCreated.name, characterCreated.greeting));
            return;
        }
        if (type == typeof(StoryInitiated))
        {
            StoryInitiated     dialogueInitiated = (StoryInitiated)evt;
            CharacterReadModel character         = (CharacterReadModel)table.GetModel(dialogueInitiated.characterName);
            character.currentText = dialogueInitiated.initialNode.text;
            character.currentStorylineCompleted = false;
            table.UpdateModel(dialogueInitiated.characterName, character);              //not necessary, since we are mutating the reference,
            //but like to be explicit and will soon move to immutable structs for readmodels.
            return;
        }
        if (type == typeof(StoryAdvanced))
        {
            StoryAdvanced      dialogueAdvanced = (StoryAdvanced)evt;
            CharacterReadModel character        = (CharacterReadModel)table.GetModel(dialogueAdvanced.characterName);
            character.currentText = dialogueAdvanced.newNode.text;
            table.UpdateModel(dialogueAdvanced.characterName, character);
            return;
        }
        if (type == typeof(StoryCompleted))
        {
            StoryCompleted     storylineCompleted = (StoryCompleted)evt;
            CharacterReadModel character          = (CharacterReadModel)table.GetModel(storylineCompleted.characterName);
            character.currentText = character.goodbye;
            character.currentStorylineCompleted = true;
            table.UpdateModel(storylineCompleted.characterName, character);
        }
    }
Esempio n. 10
0
    /// <summary>
    /// Constructor of the QLearner
    /// </summary>
    /// <param name="stateExtractor"></param>
    /// The mower, that is learning
    /// <param name="mower"></param>
    ///
    /// The following are all classic QLearning parameters,
    /// with values in between 0 and 1:
    ///
    /// Greediness of the Q learning algorithm
    /// <param name="greediness"></param>
    /// Discountvalue: How much are old experiences weighted
    /// <param name="discountValue"></param>
    /// How fast or slow shall the mower learn?
    /// Fast: High value, slow: low value
    /// <param name="learnRate"></param>
    ///
    /// "Special" parameters:
    ///
    /// QLearning with optimitstic initial values
    /// <param name="initialQValue"></param>
    /// File to load the qTable from. Can be null.
    /// <param name="qTableDeserializationFile">
    /// File to write the qTable to after the episode limit is reached.
    /// <param name="qTableSerializationFile">
    /// Running with ETraces, yes or no?
    /// <param name="eligTraces"></param>
    /// If so, with what gamma?
    /// <param name="gamma"></param>
    /// File to load the EligibilityTable from. Can be null.
    /// <param name="eTableDeserializationFile">
    /// File to write the EligibilityTable to after the episode limit is reached.
    /// <param name="eTableSerializationFile">
    /// Running with Model?
    /// <param name="modelPlanning"></param>
    /// Using refined (true) or DynaQ (false) model
    /// <param name="refined"></param>
    /// File to load the Model from. Can be null.
    /// <param name="modelTableDeserializationFile">
    /// File to write the Model to after the episode limit is reached.
    /// <param name="modelTableSerializationFile">
    /// How many N virtual steps are executed in the model?
    /// <param name="n"></param>
    /// Shall the parameter label be shown?
    /// <param name="showParamLabel"></param>

    public QLearner(StateExtractor stateExtractor,
                    Mower mower,
                    float greediness,
                    float discountValue,
                    float learnRate,
                    float initialQValue,
                    string qTableDeserializationFile,
                    string qTableSerializationFile,
                    bool eligTraces,
                    float gamma,
                    string eTableDeserializationFile,
                    string eTableSerializationFile,
                    bool modelPlanning,
                    bool refined,
                    string modelTableDeserializationFile,
                    string modelTableSerializationFile,
                    int n,
                    bool showParamLabel)
        : base(stateExtractor)
    {
        Greediness               = greediness;
        DiscountValue            = discountValue;
        LearnRate                = learnRate;
        InitialQValue            = initialQValue;
        _qTableSerializationFile = qTableSerializationFile;
        _qTable                      = new QTable(InitialQValue, qTableDeserializationFile);
        Run_with_etraces             = eligTraces;
        Gamma                        = gamma;
        _eTableSerializationFile     = eTableSerializationFile;
        ModelPlanning                = modelPlanning;
        Refined                      = refined;
        _modelTableSerializationFile = modelTableSerializationFile;
        if (Run_with_etraces)
        {
            _eTable = new EligibilityTable(0f, eTableDeserializationFile);
        }
        if (ModelPlanning)
        {
            if (refined)
            {
                _mTable = new ModelTable(mower, modelTableDeserializationFile);
            }
            else
            {
                _simpleMTable = new ModelTableSimple(0f, modelTableDeserializationFile);
            }
        }

        N = n;
        _showParamLabel = showParamLabel;

        Debug.Log(string.Format(
                      "QLearner instantiated with greediness:{0}, discountValue:{1}, learnRate:{2}, initialQValue:{3}, N for Model:{4}",
                      Greediness,
                      DiscountValue,
                      LearnRate,
                      InitialQValue,
                      N));

        EpisodeManager.AddEpisodeChangesReceiver(this);
    }
        public async Task <ActionResult <ModelTable> > PostModel([FromBody] ModelTable model, string option = "save")
        {
            option = option.Replace("\"", "");
            if (!_modelOptions.Contains(option))
            {
                return(BadRequest("Invalid option: valid values are: \"save\", \"saveandrun\", \"saveandtrain\""));
            }
            //Check if Tenant and User Id exists
            if (await _context.Users.FindAsync(model.UserId) == null)
            {
                return(NotFound());
            }

            //Create new Model object
            ModelTable newModel = new ModelTable
            {
                ModelName     = model.ModelName,
                Configuration = model.Configuration,
                ModelId       = new Guid(),
                File          = null,
                Created       = DateTime.Now,
                LastUpdated   = DateTime.Now,
                UserId        = model.UserId
            };

            _context.Models.Add(newModel);
            await _context.SaveChangesAsync();

            //Run the model if the option is selected
            if (option.Equals("saveandrun"))
            {
                try
                {
                    Task.Factory.StartNew((() =>
                    {
                        backgroundTaskQueue.QueueModelRunWorkItem(model.ModelId);
                    }));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
            //Train the model if the option is selected
            if (option.Equals("saveandtrain"))
            {
                try
                {
                    Task.Factory.StartNew((() =>
                    {
                        backgroundTaskQueue.QueueModelUpdateWorkItem(model.ModelId);
                    }));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }

            return(CreatedAtAction("GetModel", new { id = newModel.ModelId }, newModel));
        }
        public async Task <ActionResult <ModelTable> > PutModel([FromBody] ModelTable updatedModel, string option = "save")
        {
            option = option.Replace("\"", "");
            if (!_modelOptions.Contains(option))
            {
                return(BadRequest("Invalid option: valid values are: \"save\", \"saveandrun\", \"saveandtrain\""));
            }

            //patch models
            var model = await _context.Models.FindAsync(updatedModel.ModelId);

            if (model == null)
            {
                return(NotFound());
            }

            model.Configuration = updatedModel.Configuration;
            model.ModelName     = updatedModel.ModelName;
            model.LastUpdated   = DateTime.Now;

            _context.Entry(model).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ModelExists(model.ModelId))
                {
                    return(NotFound());
                }
                else
                {
                    return(BadRequest("Error encountered while saving changes."));

                    throw;
                }
            }

            //Run the model if the option is selected
            if (option.Equals("saveandrun"))
            {
                try
                {
                    Task.Factory.StartNew((() =>
                    {
                        backgroundTaskQueue.QueueModelRunWorkItem(model.ModelId);
                    }));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
            //Train the model if the option is selected
            if (option.Equals("saveandtrain"))
            {
                try
                {
                    Task.Factory.StartNew((() =>
                    {
                        backgroundTaskQueue.QueueModelUpdateWorkItem(model.ModelId);
                    }));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }

            return(NoContent());
        }
Esempio n. 13
0
 public abstract void Reduce(Event evt, ModelTable table);