Exemplo n.º 1
0
        public Task Consume(ConsumeContext <PredictedResultReady> context)
        {
            var prediction      = _keyValueRepository.LoadObject <dynamic>(context.Message.Id);
            var softwareInfo    = $@"{{
                              'software': '{_sspSettings.Software}',
                              'version': '{Assembly.GetEntryAssembly().GetVersion()}'
                        }}";
            var softwareInfoObj = JsonConvert.DeserializeObject <dynamic>(softwareInfo);
            var response        = context.Message.Data;

            response.provider   = softwareInfoObj;
            prediction.response = response;

            prediction.status = "COMPLETE";
            _keyValueRepository.SaveObject(context.Message.Id, prediction);
            _keyValueRepository.SetExpiration(context.Message.Id, TimeSpan.Parse(_sspSettings.RedisExpirationTime));
            return(Task.CompletedTask);
        }
Exemplo n.º 2
0
 public static void SaveTo(this ProcessingInfo obj, IKeyValueRepository repository)
 {
     repository.SaveObject(obj.ProcessingInfoId, obj);
 }
Exemplo n.º 3
0
 public static void SaveTo(this FileDescriptor obj, IKeyValueRepository repository)
 {
     repository.SaveObject(obj.DescriptorId, obj);
 }
Exemplo n.º 4
0
        public async Task <IActionResult> CreateSingleStructurePrediction([FromBody] RunSingleStructurePrediction request)
        {
            Guid predictionId  = NewId.NextGuid();
            Guid correlationId = NewId.NextGuid();

            if (!(new string[] { "MOL", "SMILES" }.Contains(request.Format)))
            {
                return(BadRequest("Provided structure representation type not supported."));
            }

            var document = new Dictionary <string, object>();

            document.Add("predictionId", predictionId);
            document.Add("status", "CALCULATING");
            document.Add("request", new Dictionary <string, object>()
            {
                { "receivedTime", DateTimeOffset.UtcNow },
                { "query", request.Structure },
                { "type", request.Format },
                { "propertyName", request.PropertyName },
                { "models", request.ModelIds }
            });

            var models = new List <Dictionary <string, object> >();

            foreach (var modelId in request.ModelIds)
            {
                BsonDocument entityFilter = new BsonDocument("IsDeleted", new BsonDocument("$ne", true))
                                            .Add("_id", modelId);
                var modelViewResult = await _models.Aggregate().Match(entityFilter)
                                      .Project <BsonDocument>((new List <string> {
                    "Blob", "Property"
                }).ToMongoDBProjection())
                                      .FirstOrDefaultAsync();

                BsonDocument permissionFilter = new BsonDocument("IsPublic", new BsonDocument("$eq", true))
                                                .Add("_id", modelId);
                var modelPermissionResult = await _accessPermissions.Aggregate().Match(permissionFilter).FirstOrDefaultAsync();

                if (modelViewResult != null && modelPermissionResult != null)
                {
                    if (modelViewResult.GetValue("Property").ToBsonDocument().GetValue("Name").ToString() == request.PropertyName)
                    {
                        var blobId = (Guid)modelViewResult.GetValue("Blob").ToBsonDocument().GetValue("_id");
                        var bucket = modelViewResult.GetValue("Blob").ToBsonDocument().GetValue("Bucket").ToString();
                        models.Add(new Dictionary <string, object>()
                        {
                            { "Id", modelId },
                            { "Blob", new Blob {
                                  Id = blobId, Bucket = bucket
                              } }
                        }
                                   );
                    }
                    else
                    {
                        return(BadRequest($"Prediction can not be created for model with id {modelId} using parameter '{request.PropertyName}'"));
                    }
                }
                else
                {
                    return(BadRequest($"Model with id {modelId} does not exist or permission denied."));
                }
            }

            _keyValueRepository.SaveObject(predictionId, document);
            _keyValueRepository.SetExpiration(predictionId, TimeSpan.Parse(_sspSettings.RedisExpirationTime));

            await _bus.Publish(new PredictStructure(predictionId, correlationId, request.Structure, request.Format, request.PropertyName, models));

            return(Ok(new { predictionId }));
            //AcceptedAtRoute("GetPrediction", new { id = predictionId });
        }