public SatyamTaskTableEntry getMinimumTriedNewEntryForWorkerIDByTemplateAndPrice(string WorkerID, string JobTemplateType, double Price) { int noTasks = getTasksCountByJobTemplateTypeAndPrice(JobTemplateType, Price); if (noTasks == 0) { return(null); } //int num = 0; //do //{ // doneScore++; // num = getRemainingTasksLessThanADoneScoreCountByJobTemplateTypeAndPrice(JobTemplateType, doneScore, Price); //} while (num == 0); int doneScore = getMinDoneScoreByJobTemplateTypeAndPrice(JobTemplateType, Price); SatyamTaskTableEntry entry = new SatyamTaskTableEntry(); SatyamResultsTableAccess resultDB = new SatyamResultsTableAccess(); List <string> GUIDList = new List <string>(); List <int> TriedEntries = new List <int>(); for (int i = 0; i < 3; i++) { // try at most 3 times //string SQLCommandString = "SELECT TOP 1 * FROM " + TableName + " WHERE DoneScore = '" + doneScore + "' AND JobTemplateType = '" + JobTemplateType + "' ORDER BY NEWID()"; //entry = getEntry(SQLCommandString); //entry = getRandomEntry_FromTopK_ByJobTemplatePrice(JobTemplateType, Price, 10); entry = getRandomEntryByJobTemplateAndPriceAndMaxDoneScore(JobTemplateType, doneScore, Price); if (!GUIDList.Contains(entry.JobGUID)) { GUIDList.Add(entry.JobGUID); TriedEntries.AddRange(resultDB.getAllTaskIDsAWorkerHasDoneForAGUID(WorkerID, entry.JobGUID)); } // the guid might change here if multiple guid are in play with same price and job template // query by jobtemplate itself takes the whole table, too long. if (!TriedEntries.Contains(entry.ID) || WorkerID == "Testing" || WorkerID == TaskConstants.AdminID)// { break; } else { entry = null; } } //if (entry == null) //{ // entry = getRandomEntryByJobTemplateDoneScorePrice(JobTemplateType, doneScore, Price); //} resultDB.close(); return(entry); }
public SatyamTaskTableEntry getTopKNewEntryForWorkerIDByTemplateAndPrice(int K, string WorkerID, string JobTemplateType, double Price) { int noTasks = getTasksCountByJobTemplateTypeAndPrice(JobTemplateType, Price); if (noTasks == 0) { return(null); } //int num = 0; //do //{ // doneScore++; // num = getRemainingTasksLessThanADoneScoreCountByJobTemplateTypeAndPrice(JobTemplateType, doneScore, Price); //} while (num == 0); int doneScore = getMinDoneScoreByJobTemplateTypeAndPrice(JobTemplateType, Price); SatyamTaskTableEntry entry = new SatyamTaskTableEntry(); SatyamResultsTableAccess resultDB = new SatyamResultsTableAccess(); List <string> GUIDList = new List <string>(); List <int> TriedEntries = new List <int>(); for (int i = 0; i < 3; i++) { // try at most 3 times entry = getRandomEntry_FromTopK_ByJobTemplatePrice(JobTemplateType, Price, K); if (!GUIDList.Contains(entry.JobGUID)) { GUIDList.Add(entry.JobGUID); TriedEntries.AddRange(resultDB.getAllTaskIDsAWorkerHasDoneForAGUID(WorkerID, entry.JobGUID)); } // the guid might change here if multiple guid are in play with same price and job template // query by jobtemplate itself takes the whole table, too long. if (!TriedEntries.Contains(entry.ID) || WorkerID == "Testing" || WorkerID == TaskConstants.AdminID)// { break; } else { entry = null; } } if (entry == null) { // fall back to the minimum done score approach entry = getMinimumTriedNewEntryForWorkerIDByTemplateAndPrice(WorkerID, JobTemplateType, Price); } resultDB.close(); return(entry); }
public SatyamTaskTableEntry getMinimumTriedNewEntryForWorkerIDByTemplateAndPriceAndMaxDoneScore(string WorkerID, string JobTemplateType, double Price, int MaxDoneScore) { int noTasks = getTasksCountByJobTemplateTypeAndPrice(JobTemplateType, Price); if (noTasks == 0) { return(null); } int doneScore = getMinDoneScoreByJobTemplateTypeAndPrice(JobTemplateType, Price); if (doneScore >= MaxDoneScore) { return(null); } SatyamTaskTableEntry entry = new SatyamTaskTableEntry(); SatyamResultsTableAccess resultDB = new SatyamResultsTableAccess(); List <string> GUIDList = new List <string>(); List <int> TriedEntries = new List <int>(); for (int i = 0; i < 3; i++) { entry = getRandomEntryByJobTemplateAndPriceAndMaxDoneScore(JobTemplateType, doneScore, Price); if (!GUIDList.Contains(entry.JobGUID)) { GUIDList.Add(entry.JobGUID); TriedEntries.AddRange(resultDB.getAllTaskIDsAWorkerHasDoneForAGUID(WorkerID, entry.JobGUID)); } // the guid might change here if multiple guid are in play with same price and job template // query by jobtemplate itself takes the whole table, too long. if (!TriedEntries.Contains(entry.ID) || WorkerID == "Testing" || WorkerID == TaskConstants.AdminID)// { break; } else { entry = null; } } resultDB.close(); return(entry); }