Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/19/13 08:46:01 (12 years ago)
Author:
fschoepp
Message:

#1888:

  • Experiments will be saved as JSON elements within the blob store.
  • Added simple model and JSON converters.
  • Backend stores and runs experiments.
  • Updated interfaces to save/read experiments.
  • Added a binding to automatically map incoming JSON ajax requests to experiment models.
  • Added the javascript DatatypeMapper to map parameter inputs to the right html elements and vice versa.
  • Added smartwizard to generate Wizards for creating new experiments (New.cshtml).
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/OaaS/HeuristicLab.Services.Optimization.Web/Controllers/ExperimentController.cs

    r9215 r9227  
    88using HeuristicLab.Services.Optimization.ControllerService.Model;
    99using System.Web.Security;
     10using Mvc3TestApplication.Binders;
     11using HeuristicLab.Services.Optimization.ControllerService.Parsers;
    1012
    1113namespace HeuristicLab.Services.Optimization.Web.Controllers
     
    4143          foreach (var scenario in scenarios)
    4244            model.Scenarios.Add(scenario);
     45
     46          Session["experiment"] = new Experiment();
     47
    4348          return View(model);
    4449        }
     50
     51        public ActionResult New() {
     52          return Index();
     53        }
     54
     55        public Experiment Experiment { get { return Session["experiment"] as Experiment; } set { Session["experiment"] = value;} }
    4556
    4657        [HttpPost]
     
    6374            if (currentNode.title == "Experiment")
    6475              continue;
    65             experiment.Scenarios.Add(new OptimizationScenario() { Id = currentNode.title });
     76            experiment.Algorithm.Add(new Algorithm() { Name = currentNode.title });
    6677          }
    6778
     
    94105          return RedirectToAction("Edit");
    95106        }
     107
     108        [HttpPost]
     109        public JsonResult SaveExperiment([ExperimentJson] Experiment experiment) {
     110          return Json(
     111            new {
     112              Success = ControllerService.withControllerService<bool>(service => {
     113                User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
     114                return service.SaveExperiment(u, experiment);
     115              })
     116            });
     117        }
     118
     119        private JsonResult ComplexExperimentCase(string scenario) {
     120          // complex case, find children of experiment
     121          var model = new GetParametersModel() { Type = "Complex" };
     122          model.Subnames = new List<string>();
     123
     124          var experiment = ControllerService.withControllerService<Experiment>(service => {
     125            User user = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
     126            return service.GetExperimentByName(user, scenario);
     127          });
     128
     129          // TODO: Make a tree out of subnames!!
     130          if (experiment != null)
     131            foreach (var algo in experiment.Algorithm)
     132              model.Subnames.Add(algo.Name);
     133
     134          return Json(model, JsonRequestBehavior.AllowGet);
     135        }
     136
     137        [HttpGet]
     138        public JsonResult GetParameters(string scenario, string context, int index) {
     139          if (context == "Experiment" || context == null) {
     140            var optimizationScenario = ControllerService.withControllerService<OptimizationScenario>(service => {
     141              return service.GetOptimizationScenarioByName(scenario);
     142            });
     143
     144            if (optimizationScenario != null) {
     145              var model = new GetParametersModel() { Type = "Basic" };
     146              model.Algorithm = optimizationScenario.FirstAlgorithm;
     147              model.Algorithm.Mapper = optimizationScenario.Id;
     148              var json = Json(model, JsonRequestBehavior.AllowGet);
     149              return json;
     150            }
     151            else {
     152              // complex case, find children of experiment
     153              var model = new GetParametersModel() { Type = "Complex" };
     154              model.Subnames = new List<string>();
     155
     156              var experiment = ControllerService.withControllerService<Experiment>(service => {
     157                User user = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
     158                return service.GetExperimentByName(user, scenario);
     159              });
     160
     161              // TODO: Make a tree out of subnames!!
     162              if (experiment != null)
     163                foreach (var algo in experiment.Algorithm)
     164                  model.Subnames.Add(algo.Name);
     165
     166              return Json(model, JsonRequestBehavior.AllowGet);
     167            }
     168          }
     169          else {
     170            var experiment = ControllerService.withControllerService<Experiment>(service => {
     171              User u = new User() { Username = Membership.GetUser().UserName, Password = Session["pw"] as string };
     172              return service.GetExperimentByName(u, context);
     173            });
     174
     175            // if child algorithm is a complex algorithm, return as such
     176            if (experiment.Algorithm[index].ChildAlgorithms.Count > 0) {
     177              var model = new GetParametersModel() { Type = "Complex" };
     178              model.Subnames = new List<string>();
     179              foreach (var algo in experiment.Algorithm[index].ChildAlgorithms)
     180                model.Subnames.Add(algo.Name);
     181              return Json(model, JsonRequestBehavior.AllowGet);
     182            }
     183            else {
     184              // otherwise we have the algorithms just below it
     185              var model = new GetParametersModel() { Type = "Basic" };
     186              model.Algorithm = experiment.Algorithm[index];
     187              model.Algorithm.Mapper = experiment.Algorithm[index].Name;
     188              var json = Json(model, JsonRequestBehavior.AllowGet);
     189              return json;
     190            }
     191          }
     192        }
    96193    }
    97194}
Note: See TracChangeset for help on using the changeset viewer.