/******************** State Management Methods ********************/ private async Task SetTheSearchRequestStatus(Status newStatus) { BESearchRequest newSearchRequest = await GetTheSearchRequest(); newSearchRequest.TheStatus = newStatus; await SaveTheSearchRequest(newSearchRequest); }
private async Task calculateResults() { BESearchRequest theSearchRequest = await GetTheSearchRequest(); float posScore = 0; float negScore = 0; int totalTextsNum = 0; IEnumerable <MinerData> minerDatum = await dbHandlerService.GetMinerDatum(theSearchRequest.ActiveExecutionID); foreach (var minerData in minerDatum) { posScore += minerData.ThePositivesNum; negScore += minerData.TheNegativesNum; totalTextsNum += minerData.TheTextsNum; } // Presenation: Nerf Neutral results float nerfFactor = 0.6F; var theNeutralsNum = totalTextsNum - posScore - negScore; theNeutralsNum *= nerfFactor; totalTextsNum -= (int)Math.Round(theNeutralsNum); posScore /= totalTextsNum; negScore /= totalTextsNum; posScore *= 100F; negScore *= 100F; await SaveTheResults(new Results( posScore, negScore )); }
public async Task UpdateBESearchRequest(BESearchRequest updatedBESearchRequest) { using (var db = new BEMainDBContext()) { db.BESearchRequests.AddOrUpdate(updatedBESearchRequest); await db.SaveChangesAsync(); } }
// Updates all the necessary DB Entries when the SearchRequest is successfully fulfilled private async Task updateDBEntries() { BESearchRequest theSearchRequest = await GetTheSearchRequest(); Results theResults = await GetTheResults(); await dbHandlerService.UpdateSearchRequestFulfilled(theSearchRequest.ID, theSearchRequest.ActiveExecutionID, theResults); }
/******************** Actor Interface Methods ********************/ public virtual async Task StartMiningAsync(BESearchRequest searchRequest) { // Initialize the SearchRequest in the state manager await SaveTheSearchRequest(searchRequest); // Set the Reminder for the method to begin Mining await RegisterReminderAsync(ReminderNames.MineBeginReminder); }
/******************** Actor Interface Methods ********************/ public async Task StartAnalysingAsync(BESearchRequest searchRequest) { // Initialize the values stored in the State Manager await SaveTheSearchRequest(searchRequest); // Set the Reminder for the method that implements the core logic of the Actor () await RegisterReminderAsync(ReminderNames.AnalyseBeginReminder); }
public async Task <BESearchRequest> GetBESearchRequest(int id) { BESearchRequest bESearchRequest = null; using (var db = new BEMainDBContext()) { bESearchRequest = await db.BESearchRequests.FindAsync(id); } return(bESearchRequest); }
// Called before the Miner starts its job (mainMineAsync) protected virtual async Task onMineBeginAsync() { // Initialize the MinerData for this Execution BESearchRequest theSearchRequest = await GetTheSearchRequest(); MinerData theMinerData = new MinerData(theSearchRequest.ActiveExecutionID, TheSourceID); await SaveTheMinerData(theMinerData); }
public async Task <BESearchRequest> PostBESearchRequest(BESearchRequest newBESearchRequest) { BESearchRequest createdBESearchRequest; using (var db = new BEMainDBContext()) { createdBESearchRequest = db.BESearchRequests.Add(newBESearchRequest); await db.SaveChangesAsync(); } return(createdBESearchRequest); }
/************************* Internal Methods *************************/ // Creates the BEExecution, in a Reliable way (if it hasn't already been created) private async Task initExecution(BESearchRequest theSearchRequest) { if (theSearchRequest.hasCreatedLastExecution() == false) { BEExecution createdBEExecution = await dbHandlerService.StoreExecution( new BEExecution( theSearchRequest.ID, DateTime.Now, null )); theSearchRequest.ActiveExecutionID = createdBEExecution.ID; await SaveTheSearchRequest(theSearchRequest); } }
/******************** Actor Interface Methods ********************/ public async Task FulfillSearchRequestAsync(BESearchRequest searchRequest) { // Initialize the values stored in the State Manager await SaveTheSearchRequest(searchRequest); await SaveTheSourcesLeft(NewStateNames.TheMinersToCreate, searchRequest.TheSelectedSources); await SaveTheSourcesLeft(NewStateNames.TheMinersToFinish, searchRequest.TheSelectedSources); await SaveTheSourcesLeft(NewStateNames.TheAnalysersToCreate, searchRequest.TheSelectedSources); await SaveTheSourcesLeft(NewStateNames.TheAnalysersToFinish, searchRequest.TheSelectedSources); // Set the Reminder for the method that implements the core logic of the Actor (mainFulfillSearchRequestAsync) await RegisterReminderAsync(ReminderNames.FulfillSReqReminder); }
public BESearchRequest GetBESearchRequestByReceived(int receivedID) { BESearchRequest theBESReq = null; using (var db = new BEMainDBContext()) { theBESReq = db.BESearchRequests .Where(sReq => sReq.TheReceivedID == receivedID) .ToList() .FirstOrDefault(); } return(theBESReq); }
/******************** Actor Logic Implementation Methods ********************/ // Fullfills the SearchRequest. private async Task mainFulfillSearchRequestAsync() { BESearchRequest theSearchRequest = await GetTheSearchRequest(); Status theStatus = theSearchRequest.TheStatus; switch (theStatus) { case Status.New: await initExecution(theSearchRequest); await activateMiners(theSearchRequest); // All Miners were created successfully await UpdateSearchRequestStatus(Status.Mining, 0); break; case Status.Mining: await activateAnalysers(theSearchRequest); break; case Status.Mining_Done: await activateAnalysers(theSearchRequest); // All Analysers were created successfully await UpdateSearchRequestStatus(Status.Analysing, 0); break; case Status.Analysing: break; case Status.Analysing_Done: if ((await GetTheResults() == null)) { await calculateResults(); } await UpdateSearchRequestStatus(Status.Fulfilled, 0); break; case Status.Fulfilled: await updateDBEntries(); // Set a Reminder to Send the Results to the Website await RegisterReminderAsync(ReminderNames.SendResultsReminder); break; } }
public async Task UpdateSearchRequestFulfilled(int searchRequestID, int executionID, Results theResults) { BESearchRequest theSReq = await TheSReqsContr.GetBESearchRequest(searchRequestID); theSReq.TheStatus = Status.Fulfilled; await TheSReqsContr.UpdateBESearchRequest(theSReq); BEExecution theExec = await TheExecsContr.GetBEExecution(executionID); theExec.FinishedOn = DateTime.Now; await TheExecsContr.UpdateBEExecution(theExec); theResults.ID = executionID; await TheResultsContr.PostResults(theResults); }
/******************** Service Interface Methods ********************/ /*---------- SearchRequest Management ----------*/ public async Task <BESearchRequest> StoreOrUpdateSearchRequest(BESearchRequest newBESearchRequest) { // Check if this SearchRequest has been received again BESearchRequest theSearchRequest = TheSReqsContr.GetBESearchRequestByReceived(newBESearchRequest.TheReceivedID); if (theSearchRequest == null) // If not, create a new SearchRequest { theSearchRequest = await TheSReqsContr.PostBESearchRequest(newBESearchRequest); } else // If it has, update its Status to new, since it will be executed again { theSearchRequest.TheStatus = Status.New; await TheSReqsContr.UpdateBESearchRequest(theSearchRequest); } return(theSearchRequest); }
public async Task <IHttpActionResult> PostSearchRequest(BaseSearchRequest baseSearchRequest) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } BESearchRequest theSearchRequest; BESearchRequest newBESearchRequest = new BESearchRequest(baseSearchRequest); try { theSearchRequest = await dbHandlerService.StoreOrUpdateSearchRequest(newBESearchRequest); IMasterActor theMasterActor = ActorProxy.Create <IMasterActor>(new ActorId(theSearchRequest.ID)); await theMasterActor.FulfillSearchRequestAsync(theSearchRequest); } catch { return(InternalServerError()); } return(Ok()); }
/******************** Actor Logic Implementation Methods ********************/ // Called before the Miner starts its job (mainMineAsync) protected override async Task onMineBeginAsync() { // Initialize the TwitterData for this Execution, starting from where the previous execution finished BESearchRequest theSearchRequest = await GetTheSearchRequest(); TwitterData theTwitterData = await dbHandlerService.GetLatestTwitterData(theSearchRequest.ID); if (theTwitterData == null) { miningForFirstTime = true; theTwitterData = new TwitterData(theSearchRequest.ActiveExecutionID); } else { miningForFirstTime = false; theTwitterData.TheTextsNum = 0; theTwitterData.TheExecutionID = theSearchRequest.ActiveExecutionID; } await SaveTheMinerData(theTwitterData); }
private async Task activateAnalysers(BESearchRequest theSearchRequest) { MiningSource desiredSources = await GetTheSourcesLeft(NewStateNames.TheAnalysersToCreate); Exception exOnAnalyserCall = null; foreach (var selectedSource in desiredSources.GetAsList()) { var analyserUri = AnalyserActorsFactory.GetAnalyserUri(selectedSource); IAnalyserActor theAnalyser = ActorProxy.Create <IAnalyserActor>(new ActorId(theSearchRequest.ID), analyserUri); try { await theAnalyser.StartAnalysingAsync(theSearchRequest); await DecreaseTheSourcesLeft(NewStateNames.TheAnalysersToCreate, selectedSource); } catch (Exception ex) { exOnAnalyserCall = ex; } } if (exOnAnalyserCall != null) //An Analyser failed { throw exOnAnalyserCall; } }
/******************** Actor Interface Methods ********************/ public override async Task StartMiningAsync(BESearchRequest searchRequest) { await base.StartMiningAsync(searchRequest); }
protected async Task SaveTheSearchRequest(BESearchRequest theSearchRequest) { await StateManager.SetStateAsync(StateNames.TheSearchRequest, theSearchRequest); await SaveStateAsync(); }