- Timestamp:
- 03/20/13 16:56:28 (12 years ago)
- Location:
- branches/OaaS/HeuristicLab.Services.Optimization.Controller
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OaaS/HeuristicLab.Services.Optimization.Controller/Azure/DAL.cs
r9305 r9324 162 162 } 163 163 164 public bool Delete(string username, string experimentId) { 165 TableServiceContext serviceContext = TableClient.GetDataServiceContext(); 166 TableClient.CreateTableIfNotExist(AzureConstants.EXPERIMENT_TABLE); 167 var entity = (from e in serviceContext.CreateQuery<ExperimentEntity>(AzureConstants.EXPERIMENT_TABLE) 168 where e.ExperimentId == experimentId 169 select e).FirstOrDefault(); 170 171 if (entity == null) 172 return false; 173 174 if (entity.ExperimentJsonUrl != null) { 175 CloudBlobContainer container = BlobClient.GetContainerReference(AzureConstants.EXPERIMENT_BLOB_CONTAINER); 176 container.CreateIfNotExist(); 177 var blob = container.GetBlobReference(entity.ExperimentJsonUrl); 178 blob.DeleteIfExists(); 179 } 180 181 serviceContext.DeleteObject(entity); 182 serviceContext.SaveChangesWithRetries(); 183 return true; 184 } 185 164 186 public bool DeleteByName(string username, string experiment) { 165 187 TableServiceContext serviceContext = TableClient.GetDataServiceContext(); … … 209 231 //} 210 232 211 public IEnumerable<Model.Experiment> GetExperiments(string user ) {233 public IEnumerable<Model.Experiment> GetExperiments(string user, bool namesOnly=false) { 212 234 TableServiceContext serviceContext = TableClient.GetDataServiceContext(); 213 235 TableClient.CreateTableIfNotExist(AzureConstants.EXPERIMENT_TABLE); … … 216 238 select e).ToList(); 217 239 var experiments = new List<Experiment>(); 218 CloudBlobContainer container = BlobClient.GetContainerReference(AzureConstants.EXPERIMENT_BLOB_CONTAINER); 219 container.CreateIfNotExist(); 220 foreach (var entity in entites) { 221 var blob = container.GetBlobReference(entity.ExperimentJsonUrl); 222 experiments.Add(AlgorithmConverter.ConvertJsonToExperiment(blob.DownloadText())); 223 } 224 return experiments; 240 if (namesOnly) { 241 return (from e in entites select new Model.Experiment() { Id = e.ExperimentId, Name = e.RowKey.Split('_')[1] }); 242 } 243 else { 244 CloudBlobContainer container = BlobClient.GetContainerReference(AzureConstants.EXPERIMENT_BLOB_CONTAINER); 245 container.CreateIfNotExist(); 246 foreach (var entity in entites) { 247 var blob = container.GetBlobReference(entity.ExperimentJsonUrl); 248 experiments.Add(AlgorithmConverter.ConvertJsonToExperiment(blob.DownloadText())); 249 } 250 return experiments; 251 } 225 252 } 226 253 -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/HL/HiveScenarioManager.cs
r9305 r9324 336 336 else if (item is DoubleMatrix) { 337 337 var matrix = item as DoubleMatrix; 338 double[][] matrixValue = new double[matrix.Rows][];338 /*double[][] matrixValue = new double[matrix.Rows][]; 339 339 for (int i = 0; i < matrixValue.Length; ++i) { 340 340 matrixValue[i] = new double[matrix.Columns]; … … 342 342 matrixValue[i][j] = matrix[i, j]; 343 343 } 344 } 345 result.Value = new HeuristicLab.Services.Optimization.ControllerService.Model.DecimalMatrix() { Name = name, Value = matrixValue }; 344 } */ 345 double[][] matrixValue = new double[matrix.Columns][]; 346 for (int i = 0; i < matrix.Columns; ++i) { 347 matrixValue[i] = new double[matrix.Rows]; 348 for (int j = 0; j < matrix.Rows; ++j) { 349 matrixValue[i][j] = matrix[j, i]; 350 } 351 } 352 result.Value = new HeuristicLab.Services.Optimization.ControllerService.Model.DecimalMatrix() { Name = name, Value = matrixValue, RowNames = (matrix.ColumnNames.Count() > 0 ? matrix.ColumnNames.ToArray() : null) }; 346 353 } 347 354 else if (item is IStringConvertibleArray) { … … 369 376 var columns = table.Rows.ToList()[i]; 370 377 names[i] = columns.Name; 371 results[i] = new double[columns.Values.Count]; 378 results[i] = new double[columns.Values.Count]; 372 379 for (int j=0; j < columns.Values.Count; j++) { 373 380 results[i][j] = columns.Values[j]; 374 381 } 375 382 } 383 results = transpose(results); 376 384 result.Value = new HeuristicLab.Services.Optimization.ControllerService.Model.DecimalMatrix() { Name = name, Value = results, RowNames = names }; 377 385 } … … 437 445 } 438 446 447 private double[][] transpose(double[][] arr) { 448 var width = arr.Length; 449 var height = arr[0].Length; 450 451 var res = new double[height][]; 452 for (var i = 0; i < height; i++) 453 res[i] = new double[width]; 454 455 for (var i = 0; i < width; i++) { 456 for (var j = 0; j < height; j++) { 457 res[j][i] = arr[i][j]; 458 } 459 } 460 return res; 461 } 462 439 463 private string GetMapperFromBlobStore(string scenarioName) { 440 464 var scenarioDao = dal.ScenarioDao; … … 482 506 483 507 public bool DeleteExperiment(User user, string experiment) { 484 return dal.ExperimentDao.Delete ByName(user.Username, experiment);508 return dal.ExperimentDao.Delete(user.Username, experiment); 485 509 } 486 510 … … 564 588 } 565 589 566 public IEnumerable<Model.Experiment> GetExperiments(User user ) {567 return dal.ExperimentDao.GetExperiments(user.Username );590 public IEnumerable<Model.Experiment> GetExperiments(User user, bool namesOnly=false) { 591 return dal.ExperimentDao.GetExperiments(user.Username, namesOnly); 568 592 } 569 593 -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/Interfaces/DAL.cs
r9305 r9324 22 22 bool Update(string username, Experiment experiment); 23 23 bool DeleteByName(string username, string experiment); 24 bool Delete(string username, string experimentId); 24 25 Experiment FindByName(string username, string experiment); 25 IEnumerable<Experiment> GetExperiments(string user );26 IEnumerable<Experiment> GetExperiments(string user, bool namesOnly = false); 26 27 Experiment GetExperimentByName(string username, string scenario); 27 28 -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/Interfaces/IControllerService.cs
r9305 r9324 50 50 51 51 [OperationContract] 52 IEnumerable<Experiment> GetExperiments(User user );52 IEnumerable<Experiment> GetExperiments(User user, bool namesOnly = false); 53 53 54 54 [OperationContract] -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/Interfaces/IScenarioManager.cs
r9305 r9324 17 17 string SaveExperiment(User user, Experiment experiment); 18 18 IEnumerable<string> GetExperimentNames(User user); 19 IEnumerable<Model.Experiment> GetExperiments(User user );19 IEnumerable<Model.Experiment> GetExperiments(User user, bool namesOnly = false); 20 20 Experiment GetExperimentByName(User user, string scenario); 21 21 Experiment GetExperimentById(User user, string nodeId); -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/Mockup/MockupScenarioManager.cs
r9305 r9324 279 279 } 280 280 281 public IEnumerable<Model.Experiment> GetExperiments(User user ) {281 public IEnumerable<Model.Experiment> GetExperiments(User user, bool namesOnly = false) { 282 282 throw new NotImplementedException(); 283 283 } -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/Parsers/AlgorithmConverter.cs
r9305 r9324 184 184 } 185 185 186 public static JObject ConvertRunToJson(Run run) { 187 var jrun = new JObject(); 188 jrun["id"] = run.Id; 189 jrun["name"] = run.Name; 190 jrun["results"] = ConvertParametersToJson(run.Results); 191 return jrun; 192 } 193 194 public static JArray ConvertRunsToJson(IList<Run> runs) { 195 var jarray = new JArray(); 196 foreach (var run in runs) 197 jarray.Add(ConvertRunToJson(run)); 198 return jarray; 199 } 200 186 201 public static Experiment ConvertJsonToExperiment(string json) { 187 202 var experiment = new Experiment(); -
branches/OaaS/HeuristicLab.Services.Optimization.Controller/PlaceholderControllerService.cs
r9305 r9324 185 185 186 186 187 public IEnumerable<Experiment> GetExperiments(User user ) {188 return hiveManager.GetExperiments(user );187 public IEnumerable<Experiment> GetExperiments(User user, bool namesOnly=false) { 188 return hiveManager.GetExperiments(user, namesOnly); 189 189 } 190 190
Note: See TracChangeset
for help on using the changeset viewer.