Difference between revisions of "DataCacheSpecification class"

From Catglobe Wiki
Jump to: navigation, search
Line 184: Line 184:
 
string freeTextFilters  = "UserId: [39149 TO 47878]";
 
string freeTextFilters  = "UserId: [39149 TO 47878]";
 
dcs.EvalWhere(d,"","",freeTextFilters);
 
dcs.EvalWhere(d,"","",freeTextFilters);
 +
</source>
 +
'''Ex 8:''' CreateAllColumnsForQuestions
 +
<source lang="javascript">
 +
//*****Example for using CreateAllColumnsForQuestions*****//
 +
//Constructor a DCS
 +
number DCSRId = 15572568;
 +
DataCacheSpecification dcs = new DataCacheSpecification(DCSRId);
 +
//Add columns into the DCS
 +
number qnaireRId = 15572331;// any qnaire that you want to add columns to the above DCS 
 +
array questionsLabel = {"District", "Age"};
 +
Dictionary d = dcs.CreateAllColumnsForQuestions(questionsLabel, qnaireRId);//{"Age": {QcsQuestionColumn}, "District": {QcsQuestionColumn}}
 +
array arrayQcsColumn = d.Values;//{{QcsQuestionColumn},{QcsQuestionColumn}}
 +
 +
for(number i=0;i<arrayQcsColumn.Count; i++)
 +
{
 +
array QcsColumn = arrayQcsColumn[i];//{QcsQuestionColumn}
 +
for(number j=0; j<QcsColumn.Count; j++)
 +
{
 +
QcsQuestionColumn col = QcsColumn[j];
 +
col.Save();
 +
}
 +
}
 +
//Save DCS
 +
dcs.Save();
 
</source>
 
</source>
 
[[Category:Classes]]
 
[[Category:Classes]]

Revision as of 05:24, 7 June 2017

DataCacheSpecification



Represents a DataCache specification.

Constructors

  • () - Instanciate an existing instance using the current context datacache
  • (int ResourceId "Resource Id of the DataCache") - Instanciate an existing instance using the resource id of a datacache
  • (string ResourceName "Resource name of the new DataCache", array Questionnaire Ids "List of Questionnaires to use in the creation. Must all belong to same template") - Create a new datacache using quick setup

Methods

  • Empty AddFilter(string filterQuestionLabel "Question to apply filter to. If empty, then clear current filters", string filterValue "Value of the filter") - Add a filter to the DataCache
  • bool AddQuestionnaire(int questionnaireResourceId "Questionnaire to add") - Add another questionnaire to the datacache. Return false if already added
  • array CreateAllColumnsForAllQuestions(int questionnaireResourceId "Set the associated questionnaire. Set to 0 to use primary questionnaire") - Find and create all column for all questions. They still need to be saved individually to be added.
  • array CreateAllColumnsForQuestion(string question "QuestionLabel for the question you want all the dcs columns for", int questionnaireResourceId "Set the associated questionnaire. Set to 0 to use primary questionnaire") - Find and create all column for a given question. They still need to be saved individually to be added.
  • Dictionary CreateAllColumnsForQuestions(array questions "QuestionLabels for the questions you want all the dcs columns for", int questionnaireResourceId "Set the associated questionnaire. Set to 0 to use primary questionnaire") - Find and create all column for a given question. They still need to be saved individually to be added.
  • object EvalWhere(string whereExpression "The expression to execute. It must contain 'where' and NOT start with a equal sign, and have 1 and only one semicolon in it") - Evaluate a single where expression up against the current DataCache
  • Dictionary EvalWhere(Dictionary whereExpressions "The expressions to execute. They must contain 'where' and MAY start with a equal sign, and have 1 and only one semicolon in it") - Evaluate a number of where expressions up against the current DataCache. If there are 2 or more expressions, the result is cached. Context weight and filters are ignored.
  • Dictionary EvalWhere(Dictionary whereExpressions "The expressions to execute. They must contain 'where' and MAY start with a equal sign, and have 1 and only one semicolon in it", string weight "Column name of the weight to use in filter") - Evaluate a number of where expressions up against the current DataCache using a weight. If there are 2 or more expressions, the result is cached. Context weight and filters are ignored.
  • Dictionary EvalWhere(Dictionary whereExpressions "The expressions to execute. They must contain 'where' and MAY start with a equal sign, and have 1 and only one semicolon in it", string weight "Column name of the weight to use in filter", string filters "Extra filters that apply to all where expressions") - Evaluate a number of where expressions up against the current DataCache using a weight. If there are 2 or more expressions, the result is cached. Context weight and filters are ignored.
  • Dictionary EvalWhere(Dictionary whereExpressions "The expressions to execute. They must contain 'where' and MAY start with a equal sign, and have 1 and only one semicolon in it", string weight "Column name of the weight to use in filter", string filters "Extra filters that apply to all where expressions", string freeTextFilters "Extra free text search filters that apply to all where expressions") - Evaluate a number of where expressions up against the current DataCache using a weight. If there are 2 or more expressions, the result is cached. Context weight and filters are ignored.
  • Empty MakeContext() - Make the current DataCache the context DataCache
  • Empty Reset() - Reset to initial quick setup
  • Empty Save() - Save the DataCache
  • string ToString() - The string representation of the object.

Properties

  • bool AutoUpdate { get; set; } - Get/Set Auto Update
  • bool BuildWithWeight { get; set; } - Get/Set if the DataCache should be built using weights
  • int CachedRecords { get; } - How many records does the DataCache currently hold
  • array ColumnNames { get; } - List of Column names
  • array Columns { get; } - List of Column objects
  • bool Completed { get; set; } - Get/Set include completed
  • bool Deleted { get; set; } - Get/Set include deleted
  • string Description { get; set; } - Get/Set description of the DataCache
  • bool Disabled { get; set; } - Get/Set include disabled
  • bool InterviewFailed { get; set; } - Get/Set include marked as interview failed
  • bool InterviewSucceeded { get; set; } - Get/Set include marked as interview succeeded
  • bool IsOutOfDate { get; } - Does the DataCache need to be rebuilt to have the correct content
  • string Language { get; set; } - Get/Set the iso code used in building the items that depend on a specific language
  • DateTime LastUpdated { get; } - Time of the last rebuild
  • string Name { get; set; } - Name of the DataCache resource
  • bool Normal { get; set; } - Get/Set include normal
  • bool NotStarted { get; set; } - Get/Set include those not yet started
  • string ObjectTypeName { get; } - The name of the type of object.
  • bool OutsideTarget { get; set; } - Get/Set include those marked outside target
  • bool Partly { get; set; } - Get/Set include partly completed
  • ProfilingResult ProfileFromLastEval { get; } - Get the profile result from the last run of EvalWhere.
  • array QuestionnaireIds { get; } - List of the questionnaires used in the DataCache
  • int QuestionnaireTemplateId { get; } - The resource id of the questionnaire template used in the DataCache
  • bool QuotaFull { get; set; } - Get/Set include those with full quota
  • int ResourceId { get; } - The Id of the DataCache
  • bool Test { get; set; } - Get/Set include those marked as test
  • TypeInformation TypeInformation { get; } - Get information about this class.
  • int UpdateFrequence { get; set; } - Get/Set Update Frequence in minutes
  • Array of objects Weights { get; } - Get list of existing weights.



Examples

Ex1:

DCS_use(37244952); // set DCS context
string e1 = "count() where S_Age == [1] && M_Travel == [1,2];";
Dictionary d =
{
 "exp1": "count() where S_Age == [1] && M_Travel == [1,2];",
 "exp2": "count() where S_Age == [2] && M_Travel == [1];"
};
print(DCS_evaluateWhereExpression(e1)); // 68
DataCacheSpecification dcs = new DataCacheSpecification(); // Represent a DCS which is used as current DCS context
print(dcs.EvalWhere(e1)); // 68
print(dcs.EvalWhere(d)); // {"exp1": 68, "exp2": 46}


Ex2:

string e1 = "count() where S_Age == [1] && M_Travel == [1,2];";
Dictionary d =
{
 "exp1": "count() where S_Age == [1] && M_Travel == [1,2];",
 "exp2": "count() where S_Age == [2] && M_Travel == [1];"
};
DataCacheSpecification dcs = new DataCacheSpecification(37244952); // Represents a DCS which has Resource Id: 37244952
print(dcs.EvalWhere(e1)); // 68
print(dcs.EvalWhere(d)); // {"exp1": 68, "exp2": 46}
dcs.MakeContext(); // or you can use DCS_use(RID) instead
print(DCS_evaluateWhereExpression(e1)); // without the previous statement (dcs.MakeContext();), you will get error at this line because there is no DCS context is set, so you can not use DCS_evaluateWhereExpression(e1)
dcs.Partly = false; // Not include the partly completed QASs
dcs.NotStarted = false; // Not include the not started QASs
dcs.Save(); // Must save to make the above statements applied on DCS, but this statement does not REBUILD the DCS


Ex 3:

ProfilingResult pr;
DataCacheSpecification dcs = new DataCacheSpecification(12006923); 
pr = dcs.ProfileFromLastEval;
pr.EnableProfiling = true;
dcs.EvalWhere({
 "ex1": "count() where true"
});

print(pr.CompileTime); // 0.1694
print(pr.CountResult); // {"5": {"2": 1}, "9": {"4": 1}} 
print(pr.DependencyGraphTime); // 0
print(pr.TimeResult); // {"10": {"-1": 0.0158, "4": 0.0158}, "11": {"-1": 0.0021, "4": 0.0021}, "5": {"-1": 1.1024, "2": 1.1024}, "9": {"-1": 0.0063, "4": 0.0063}}
print(pr.WhereExpTime); // 0


Ex 4:

DataCacheSpecification dcs = new DataCacheSpecification(15517146);

array questionColumns = dcs.CreateAllColumnsForQuestion("Q1",0); //Create new column(s) for a question and use primary questionnaire 

for(number i= 0; i < questionColumns.Count; i++){
 questionColumns[i].Save(); //or method .Delete() in case removing column from dcs
}
dcs.Save(); //Must save to make the above statements applied on DCS, but this statement does not REBUILD the DCS
print(dcs.ColumnNames);


Ex 5:

DataCacheSpecification dcs = new DataCacheSpecification(15517146);

array questionColumns = dcs.CreateAllColumnsForAllQuestions(15517148); //Create ALL columns for ALL questions.Set to 0 to use primary questionnaire

for(number i= 0; i < questionColumns.Count; i++){
 questionColumns[i].Save();
}
dcs.Save(); //Must save to make the above statements applied on DCS, but this statement does not REBUILD the DCS
print(dcs.ColumnNames);


Ex 6:

DataCacheSpecification dcs = new DataCacheSpecification(15558382);
dcs.AddQuestionnaire(15558383);
dcs.Save();

Ex 7: Using freeTextFilters on EvalWhere

DataCacheSpecification dcs = new DataCacheSpecification(15557696);
Dictionary d ={
	"exp": "selectColumn(Id) where true;"
};
string freeTextFilters  = "UserId: [39149 TO 47878]";
dcs.EvalWhere(d,"","",freeTextFilters);

Ex 8: CreateAllColumnsForQuestions

//*****Example for using CreateAllColumnsForQuestions*****//
//Constructor a DCS
number DCSRId = 15572568;
DataCacheSpecification dcs = new DataCacheSpecification(DCSRId);
//Add columns into the DCS
number qnaireRId = 15572331;// any qnaire that you want to add columns to the above DCS  
array questionsLabel = {"District", "Age"};
Dictionary d = dcs.CreateAllColumnsForQuestions(questionsLabel, qnaireRId);//{"Age": {QcsQuestionColumn}, "District": {QcsQuestionColumn}}
array arrayQcsColumn = d.Values;//{{QcsQuestionColumn},{QcsQuestionColumn}}

for(number i=0;i<arrayQcsColumn.Count; i++)
{
	array QcsColumn = arrayQcsColumn[i];//{QcsQuestionColumn}
	for(number j=0; j<QcsColumn.Count; j++)
	{
		QcsQuestionColumn col = QcsColumn[j];
		col.Save();
	}
}
//Save DCS
dcs.Save();