public void ConceptModelShouldBeCorrectlyDeserialized()
        {
            var          json  = JsonConvert.DeserializeObject <dynamic>(@"
{
    ""id"": ""some-model-id"",
    ""name"": ""general-v1.3"",
    ""created_at"": ""2016-03-09T17:11:39.608845Z"",
    ""app_id"": ""main"",
    ""output_info"": {
        ""message"": ""Show output_info with: GET /models/{model_id}/output_info"",
        ""type"": ""concept"",
        ""type_ext"": ""concept""
    },
    ""model_version"": {
        ""id"": ""some-model-version-id"",
        ""created_at"": ""2016-07-13T01:19:12.147644Z"",
        ""status"": {
            ""code"": 21100,
            ""description"": ""Model trained successfully""
        }
    }
}");
            ConceptModel model = ConceptModel.Deserialize(null, json);

            Assert.AreEqual("some-model-id", model.ModelID);
            Assert.AreEqual("general-v1.3", model.Name);
            Assert.AreEqual("main", model.AppID);
            Assert.AreEqual("some-model-version-id", model.ModelVersion.ID);
            Assert.AreEqual(21100, model.ModelVersion.Status.StatusCode);
        }
        public async Task ShorthandGetModelInputsShouldBeSuccessful()
        {
            /*
             * Create a model.
             */
            string modelID = GenerateRandomID();
            ClarifaiResponse <ConceptModel> createModelResponse = await Client.CreateModel(
                modelID,
                concepts : new List <Concept> {
                new Concept("cat")
            })
                                                                  .ExecuteAsync();

            Assert.True(createModelResponse.IsSuccessful);

            try
            {
                ConceptModel model = createModelResponse.Get();
                var          getModelInputsResponse = await model.GetModelInputs().ExecuteAsync();

                Assert.True(getModelInputsResponse.IsSuccessful);
                Assert.NotNull(getModelInputsResponse.Get());
            }
            finally
            {
                /*
                 * Delete the model.
                 */
                var deleteResponse = await Client.DeleteModel(modelID)
                                     .ExecuteAsync();

                Assert.True(deleteResponse.IsSuccessful);
            }
        }
Beispiel #3
0
        public async Task ShorthandDeleteModelVersionRequestShouldBeSuccessful()
        {
            string modelID = GenerateRandomID();

            ClarifaiResponse <ConceptModel> createResponse
                = await Client.CreateModel(
                      modelID,
                      name : modelID,
                      concepts : new List <Concept> {
                new Concept("dog"), new Concept("cat")
            })
                  .ExecuteAsync();

            AssertResponseSuccess(createResponse);

            ConceptModel model = createResponse.Get();

            ClarifaiResponse <ModelVersion> getVersionResponse =
                await Client.GetModelVersion(modelID, model.ModelVersion.ID).ExecuteAsync();

            string modelVersionID = getVersionResponse.Get().ID;

            ClarifaiResponse <EmptyResponse> deleteVersionResponse =
                await model.DeleteModelVersion(modelVersionID).ExecuteAsync();

            AssertResponseSuccess(deleteVersionResponse);

            /*
             * The model version should not exist anymore.
             */
            ClarifaiResponse <ModelVersion> getVersionResponse2 =
                await Client.GetModelVersion(modelID, modelVersionID).ExecuteAsync();

            Assert.False(getVersionResponse2.IsSuccessful);
        }
Beispiel #4
0
        public ActionResult DeleteConfirmed(int id, int?SummaryId)
        {
            ConceptModel conceptModel = db.Concept.Find(id);

            db.Concept.Remove(conceptModel);
            db.SaveChanges();
            return(RedirectToAction("Index", new { SummaryId = SummaryId }));
        }
 /// <summary>
 /// Open concept.
 /// </summary>
 /// <param name="conceptToCheck">Concept to check.</param>
 /// <param name="conceptToPush">Concept to push.</param>
 void openConcept(ConceptModel conceptToCheck, ConceptModel conceptToPush = null)
 {
     if (conceptToCheck.IsGroup)
     {
         _previousConcepts.Push(conceptToPush ?? conceptToCheck);
         Concepts = new List <ConceptModel>(conceptToCheck.Children);
     }
     else if (conceptToCheck.Container.Equals(_testString))
     {
         openTest(conceptToCheck.Id);
     }
 }
Beispiel #6
0
        public ActionResult Edit([Bind(Include = "ConceptId,ConceptName,EsEgreso,Amount,Payd,Prepayment,AmountPayable,PayDate,CreationDate,LastModificationDate,SummaryId")] ConceptModel conceptModel)
        {
            if (ModelState.IsValid)
            {
                db.Entry(conceptModel).State = EntityState.Modified;
                db.SaveChanges();

                concepts.UpdateAmountsSummary(conceptModel);

                return(RedirectToAction("Index", new { SummaryId = conceptModel.SummaryId }));
            }
            ViewBag.SummaryId = new SelectList(db.Summary, "SummaryId", "SummaryName", conceptModel.SummaryId);
            return(View(conceptModel));
        }
Beispiel #7
0
        // GET: Concept/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ConceptModel conceptModel = db.Concept.Find(id);

            if (conceptModel == null)
            {
                return(HttpNotFound());
            }
            return(View(conceptModel));
        }
Beispiel #8
0
        // GET: Concept/Delete/5
        public ActionResult Delete(int?id, int?SummaryId)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ConceptModel conceptModel = db.Concept.Find(id);

            if (conceptModel == null)
            {
                return(HttpNotFound());
            }
            ViewBag.SummaryId = SummaryId;
            return(View(conceptModel));
        }
Beispiel #9
0
        public async Task GetModelWithVersionIDShouldBeSuccessful()
        {
            string modelID = Client.PublicModels.GeneralModel.ModelID;
            // This is the first general model version ID.
            string modelVersionID = "aa9ca48295b37401f8af92ad1af0d91d";

            var response = await Client.GetModel <Concept>(modelID, modelVersionID)
                           .ExecuteAsync();

            ConceptModel model = (ConceptModel)response.Get();

            AssertResponseSuccess(response);

            Assert.AreEqual(modelVersionID, model.ModelVersion.ID);
            Assert.IsTrue(model.OutputInfo.Concepts.Any());
        }
Beispiel #10
0
        // GET: Concept/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ConceptModel conceptModel = db.Concept.Find(id);

            if (conceptModel == null)
            {
                return(HttpNotFound());
            }
            ViewBag.Summaries = new SelectList(db.Summary, "SummaryId", "SummaryName", conceptModel.SummaryId);
            ViewBag.SummaryId = conceptModel.SummaryId;
            return(View(conceptModel));
        }
        /// <summary>
        /// Set or open concept.
        /// </summary>
        /// <param name="selectedConcept">Selected object.</param>
        /// <param name="id">Concept ID.</param>
        void setOrOpenConcept(ConceptModel selectedConcept, int id)
        {
            if (Concepts == null)
            {
                return;
            }

            var concept = Concepts.FirstOrDefault(c => c.Id == id);

            if (concept == null)
            {
                return;
            }

            if (concept.HasData && !string.IsNullOrEmpty(concept.FilePath))
            {
                openFile(concept.FilePath);
                return;
            }

            openConcept(concept, selectedConcept);
        }
        /// <summary>
        /// Set concepts from root.
        /// </summary>
        /// <param name="id">Element ID.</param>
        /// <returns>Task.</returns>
        async Task setConceptsFromRoot(int id)
        {
            var conceptTree = await DataAccess.GetConceptTree(id);

            if (DataAccess.IsError && !DataAccess.IsConnectionError)
            {
                PlatformServices.Dialogs.ShowError(DataAccess.ErrorMessage);
            }

            var concepts = conceptTree?.Children;

            if (concepts == null)
            {
                return;
            }

            IsRoot = false;
            _previousConcepts.Push(conceptTree);
            _backupRootConceptsWithChildren = conceptTree;
            Concepts             = new List <ConceptModel>(concepts);
            IsBackActionPossible = true;
        }
        public void UpdateAmountsSummary(ConceptModel concept)
        {
            using (DataContext.DataContext db = new DataContext.DataContext())
            {
                SummaryModel summary = db.Summary.Where(t => t.SummaryId == concept.SummaryId).FirstOrDefault();

                if (summary != null)
                {
                    decimal?ConceptsPayd = 0;
                    decimal?Prepayment   = 0;

                    summary.TotalIncome  = db.Concept.Where(t => !t.EsEgreso).Sum(t => (decimal?)t.Amount);
                    summary.TotalOutcome = db.Concept.Where(t => t.EsEgreso).Sum(t => (decimal?)t.Amount);

                    //summary.TotalAmount = db.Concept.Where(t => t.SummaryId == summary.SummaryId && t.EsEgreso).Sum(t => (decimal?)t.Amount);
                    ConceptsPayd = db.Concept.Where(t => t.SummaryId == summary.SummaryId && t.Payd && t.EsEgreso).Sum(t => (decimal?)t.Amount) ?? (decimal)0;
                    Prepayment   = db.Concept.Where(t => t.SummaryId == summary.SummaryId && !t.Payd && t.Prepayment > 0).Sum(t => (decimal?)t.Prepayment) ?? (decimal)0;

                    summary.ConceptsPayd = ConceptsPayd.Value + Prepayment;

                    db.SaveChanges();
                }
            }
        }
        public async Task CreatingModifyingAndDeletingModelShouldBeSuccessful()
        {
            string modelID = GenerateRandomID();

            string originalName = "original-name";
            string newName      = "new-name";

            var originalConcepts = new List <Concept>
            {
                new Concept("dog"),
                new Concept("cat"),
            };
            var newConcepts = new List <Concept>
            {
                new Concept("horse"),
                new Concept("bird"),
            };

            try
            {
                /*
                 * Create a new model.
                 */
                ClarifaiResponse <ConceptModel> createResponse =
                    await Client.CreateModel(
                        modelID,
                        name : originalName,
                        concepts : originalConcepts,
                        areConceptsMutuallyExclusive : false,
                        isEnvironmentClosed : false)
                    .ExecuteAsync();

                Assert.True(createResponse.IsSuccessful);
                ConceptModel createdModel = createResponse.Get();
                Assert.AreEqual(modelID, createdModel.ModelID);
                Assert.AreEqual(originalName, createdModel.Name);
                Assert.AreEqual(false, createdModel.OutputInfo.AreConceptsMutuallyExclusive);
                Assert.AreEqual(false, createdModel.OutputInfo.IsEnvironmentClosed);
                Assert.AreEqual(HttpStatusCode.OK, createResponse.HttpCode);

                /*
                 * Modify the model.
                 */
                ClarifaiResponse <ConceptModel> modifyResponse =
                    await Client.ModifyModel(
                        modelID,
                        ModifyAction.Overwrite,
                        name : newName,
                        concepts : newConcepts,
                        areConceptsMutuallyExclusive : true,
                        isEnvironmentClosed : true)
                    .ExecuteAsync();

                Assert.True(modifyResponse.IsSuccessful);
                ConceptModel modifiedModel = modifyResponse.Get();
                Assert.AreEqual(modelID, modifiedModel.ModelID);
                Assert.AreEqual(newName, modifiedModel.Name);
                Assert.AreEqual(true, modifiedModel.OutputInfo.AreConceptsMutuallyExclusive);
                Assert.AreEqual(true, modifiedModel.OutputInfo.IsEnvironmentClosed);
                Assert.AreEqual(HttpStatusCode.OK, modifyResponse.HttpCode);

                /*
                 * Get the model to ensure the fields were changed.
                 */
                ClarifaiResponse <IModel <Concept> > getResponse =
                    await Client.GetModel <Concept>(modelID)
                    .ExecuteAsync();

                Assert.True(getResponse.IsSuccessful);
                IModel <Concept> retrievedModel = getResponse.Get();
                Assert.AreEqual(modelID, retrievedModel.ModelID);
                Assert.AreEqual(newName, retrievedModel.Name);
                Assert.AreEqual(HttpStatusCode.OK, getResponse.HttpCode);
                Assert.AreEqual(2, newConcepts.Count);
                Assert.IsTrue(newConcepts.Any(c => c.ID == newConcepts[0].ID));
                Assert.IsTrue(newConcepts.Any(c => c.ID == newConcepts[1].ID));
            }
            finally
            {
                /*
                 * Delete the model.
                 */
                ClarifaiResponse <EmptyResponse> deleteResponse =
                    await Client.DeleteModel(modelID).ExecuteAsync();

                Assert.True(deleteResponse.IsSuccessful);
                Assert.AreEqual(HttpStatusCode.OK, deleteResponse.HttpCode);
            }
        }
        public async Task ShorthandTrainingModelShouldBeSuccessful()
        {
            /*
             * Create a model.
             */
            string modelID             = GenerateRandomID();
            var    createModelResponse = await Client.CreateModel(
                modelID,
                concepts : new List <Concept>
            {
                new Concept("celeb"),
                new Concept("cat"),
            })
                                         .ExecuteAsync();

            ConceptModel model = createModelResponse.Get();

            /*
             * Add inputs associated with concepts.
             */
            ClarifaiResponse <List <IClarifaiInput> > addInputsResponse = await Client.AddInputs(
                new ClarifaiURLImage(CELEB1, positiveConcepts : new List <Concept> {
                new Concept("celeb")
            },
                                     allowDuplicateUrl : true),
                new ClarifaiURLImage(CAT1, positiveConcepts : new List <Concept> {
                new Concept("cat")
            },
                                     allowDuplicateUrl : true)
                ).ExecuteAsync();

            if (addInputsResponse.Status.Type != ClarifaiStatus.StatusType.Successful)
            {
                Assert.Fail("Adding inputs not successful: " + addInputsResponse.Status.Type);
            }

            /*
             * Train the model.
             */
            await model.TrainModel().ExecuteAsync();

            /*
             * Wait until the model has finished training.
             */
            int count = 0;

            while (true)
            {
                count++;
                if (count == 20)
                {
                    Assert.Fail("Model training has not finished in the allotted time.");
                }

                ClarifaiResponse <IModel <Concept> > response =
                    await Client.GetModel <Concept>(modelID).ExecuteAsync();

                ModelTrainingStatus status = response.Get().ModelVersion.Status;
                if (status.IsTerminalEvent())
                {
                    if (status.StatusCode == ModelTrainingStatus.Trained.StatusCode)
                    {
                        return;
                    }
                    Assert.Fail("The model was not trained successfully: " + status.StatusCode);
                }
                Thread.Sleep(1000);
            }
        }
Beispiel #16
0
        public async Task ModifyModelRequestAndResponseShouldBeCorrect()
        {
            var httpClient = new FkClarifaiHttpClient(
                patchResponse: @"
{
    ""status"": {
        ""code"": 10000,
        ""description"": ""Ok""
    },
    ""models"": [{
        ""id"": ""@modelID"",
        ""name"": ""@newModelName"",
        ""created_at"": ""2017-11-27T08:35:13.911899Z"",
        ""app_id"": ""@appID"",
        ""output_info"": {
            ""output_config"": {
                ""concepts_mutually_exclusive"": true,
                ""closed_environment"": true
            },
            ""message"": ""Show output_info with: GET /models/{model_id}/output_info"",
            ""type"": ""concept"",
            ""type_ext"": ""concept""
        },
        ""model_version"": {
            ""id"": ""@modelVersionID"",
            ""created_at"": ""2017-11-27T08:35:14.298376733Z"",
            ""status"": {
                ""code"": 21102,
                ""description"": ""Model not yet trained""
            }
        }
    }]
}
");
            var client   = new ClarifaiClient(httpClient);
            var response = await client.ModifyModel(
                "@modelID",
                ModifyAction.Merge,
                name : "@newModelName",
                concepts : new List <Concept> {
                new Concept("@conceptID1")
            },
                areConceptsMutuallyExclusive : true,
                isEnvironmentClosed : true)
                           .ExecuteAsync();

            var expectedRequestBody = JObject.Parse(@"
{
    ""models"": [
      {
        ""id"": ""@modelID"",
        ""name"": ""@newModelName"",
        ""output_info"": {
          ""data"": {
            ""concepts"": [
              {
                ""id"": ""@conceptID1""
              }
            ]
          },
          ""output_config"": {
            ""concepts_mutually_exclusive"": true,
            ""closed_environment"": true
          }
        }
      }
    ],
    ""action"": ""merge""
  }
");

            Assert.True(JToken.DeepEquals(expectedRequestBody, httpClient.PatchedBody));

            Assert.True(response.IsSuccessful);
            Assert.AreEqual("Ok", response.Status.Description);

            ConceptModel model = response.Get();

            Assert.AreEqual("@modelID", model.ModelID);
            Assert.AreEqual("@newModelName", model.Name);
            Assert.AreEqual("@modelVersionID", model.ModelVersion.ID);
            Assert.AreEqual(true, model.OutputInfo.AreConceptsMutuallyExclusive);
            Assert.AreEqual(true, model.OutputInfo.IsEnvironmentClosed);
        }