/* declares constant = false for any L1 compartment/parameter * assigned by a rule */ void Model::addConstantAttribute() { unsigned int n; // parameters and compartments are declared to have constant=true // by default. Since in L1 the constant attribute didnt exist // parameters/compartments that are the subjcet of rules must have // the value changed for ( n = 0; n < getNumParameters(); n++) { if (getRule(getParameter(n)->getId()) != NULL) { getParameter(n)->setConstant(false); } } for ( n = 0; n < getNumCompartments(); n++) { if (getRule(getCompartment(n)->getId()) != NULL) { getCompartment(n)->setConstant(false); } } }
bool CLuaSocketRestrictions::isAllowed(RestrictType type, const char* hostname, int port) { const TSocketRule* rule = getRule(type, hostname, port); if (rule==NULL) { return false; } return rule->allowed; }
L::Integrator::Status L::RuleIntegratorErr::integrate ( Integrand &f, const Hypercube &h, Index maxEval, real reqAbsError, real reqRelError, EstErr &ee) { checkDimension(h, f); checkTerminationCriteria (maxEval, reqAbsError, reqRelError, false); std::auto_ptr<EmbeddedRule> rule (getRule(h.getDimension())); if (maxEval < rule->getNumPoints ()) { #ifdef HINTLIB_NO_EXCEPTIONS ee.set (0.0, 0.0); return ERROR; #else throw NoEvaluationsPossible (maxEval); #endif } rule->evalError (f, h, ee); Status status = checkRequestedError (ee, reqAbsError, reqRelError); return (status == ERROR) ? MAX_EVAL_REACHED : status; }
void LessAtRule::process(Stylesheet &s) { AtRule* target = s.createAtRule(getKeyword()); target->setRule(getRule()); getLessStylesheet()->getContext()->processValue(target->getRule()); }
/* the new strict setters mean that for a conversion to L2 to * take place the model needs to think it still l1 for * some actions and think it is already L2 for others */ void Model::removeParameterRuleUnits (bool strict) { if (strict == true) { /* in L1 a parameterRule coulkd specify units * for a strict conversion this attribute should be unset */ for (unsigned int n = 0; n < getNumParameters(); n++) { if (getRule(getParameter(n)->getId()) != NULL) { getRule(getParameter(n)->getId())->unsetUnits(); } } } }
void LegacyRulePlanNode::write(FileWriter &w, CPArea parentArea) const { PlanNode::write(w, parentArea); // write rule identification including revision here w.appendIdentifier(getDatabase()->getId(),'/'); w.appendIdentifier(getCube()->getId(),'/'); w.appendIdentifier(getRule()->getId(),'/'); w.appendIdentifier((IdentifierType)getDatabase()->getObjectRevision(),0); // TODO: -jj- serialize uint64_t }
void drawFractal(char* axiom, double heading, double angle, int depth, int fractalNumber) { currX = 149 + (300 * fractalNumber); currY = 299; currH = heading; minX = 300; maxX = 0; minY = 300; maxY = 0; int dim; dim = depth; if (depth == 0) dim = 1; char masterAxiom[MAX_RULES * dim * MAX_CHARS]; strcpy(masterAxiom, axiom); char rule[MAX_RULES * dim * MAX_CHARS]; char after[MAX_RULES * dim * MAX_CHARS]; int i; for (i = 0; i < depth; i++) { int j; for (j = 0; j < strlen(masterAxiom); j++) { if ('A' <= masterAxiom[j] && masterAxiom[j] <= 'Z' || 'a' <= masterAxiom[j] && masterAxiom[j] <= 'z') { if (masterAxiom[j] != 'F' && masterAxiom[j] != 'f') { strcpy(rule, getRule(masterAxiom[j])); strcpy(after, masterAxiom+(j + 1)); strcpy(masterAxiom+j, rule); strcpy(masterAxiom+(j + strlen(rule)), after); j = j + strlen(rule) + 1; } } } } scaleAxiom(masterAxiom, angle); currX = 149 + (300 * fractalNumber); currY = 299; currH = heading; stackIndex = -1; drawAxiom(masterAxiom, angle); }
Atlas::Objects::Root RuleTreeAdapter::getSelectedRule() { CEGUI::TreeItem* item = mTreeWidget.getFirstSelectedItem(); if (item) { auto itemData = getRule(item->getText().c_str()); if (itemData.isValid()) { return itemData; } } return Atlas::Objects::Root(); }
/* converting to l1 any metaid attributes should be removed */ void Model::removeMetaId() { unsigned int n, i; unsetMetaId(); for (n = 0; n < getNumUnitDefinitions(); n++) { getUnitDefinition(n)->unsetMetaId(); for (i = 0; i < getUnitDefinition(n)->getNumUnits(); i++) { getUnitDefinition(n)->getUnit(i)->unsetMetaId(); } } for (n = 0; n < getNumCompartments(); n++) { getCompartment(n)->unsetMetaId(); } for (n = 0; n < getNumSpecies(); n++) { getSpecies(n)->unsetMetaId(); } for (n = 0; n < getNumParameters(); n++) { getParameter(n)->unsetMetaId(); } for (n = 0; n < getNumRules(); n++) { getRule(n)->unsetMetaId(); } for (n = 0; n < getNumReactions(); n++) { getReaction(n)->unsetMetaId(); for (i = 0; i < getReaction(n)->getNumReactants(); i++) { getReaction(n)->getReactant(i)->unsetMetaId(); } for (i = 0; i < getReaction(n)->getNumProducts(); i++) { getReaction(n)->getProduct(i)->unsetMetaId(); } if (getReaction(n)->isSetKineticLaw()) { getReaction(n)->getKineticLaw()->unsetMetaId(); } } }
void CLuaSocketRestrictions::addIP(const char* hostname, const char* ip) { for(int i=0; i<ALL_RULES; i++) { TStrIntMap::iterator it; for(it = restrictions[i].begin(); it != restrictions[i].end(); ++it) { const TSocketRule &rule = *it; if ((rule.hostname == hostname) && (getRule((RestrictType)i, ip, rule.port) == NULL)) { //add rule with ip, when not exisitng addRule((RestrictType)i, ip, rule.port, rule.allowed); } } } }
void RuleTreeAdapter::fetcherAllRulesReceived() { mRules = mFetcher->getRules(); std::string rootRule = mFetcher->getRootRule(); delete mFetcher; mFetcher = nullptr; const auto& root = getRule(rootRule); if (root.isValid()) { addToTree(root, nullptr, true); } EventAllRulesReceived.emit(); }
void CLuaSocketRestrictions::addRule(RestrictType type, const std::string& hostname, int port, bool allowed) { if ((port<=0) || (port>65535)){ LOG_L(L_ERROR, "Invalid port specified: %d", port); return; } if (getRule(type, hostname.c_str(), port)!=NULL) { LOG_L(L_ERROR, "Rule already exists: %s %d", hostname.c_str(), port); return; } LOG("Adding rule %d %s:%d",type, hostname.c_str(), port); if (!allowed) { //add deny rules to the front of the list restrictions[type].push_front(TSocketRule(hostname, port, allowed)); } else { restrictions[type].push_back(TSocketRule(hostname, port, allowed)); } }
void * start_routine(void * ptr){ rule_struct * myRule= NULL; while(queue_size(&rulesQueue) > 0){ pthread_mutex_lock(&mutex); while((myRule = getRule()) == NULL){ if(queue_size(&rulesQueue)) pthread_cond_wait(&cond, &mutex); else break; } pthread_mutex_unlock(&mutex); // if(myRule == NULL) return NULL; // if(depsAreFiles(myRule->rule->deps)){ if(access(myRule->rule->target, F_OK) == -1){ runRule(myRule); } else{ struct stat stat1, stat2; stat(myRule->rule->target, &stat1); int i= 0; for( ; i < queue_size(myRule->rule->deps); i++){ stat(queue_at(myRule->rule->deps, i), &stat2); if(stat2.st_mtime > stat1.st_mtime){ runRule(myRule); break; } } } } else { runRule(myRule); } //printf("queue_size= %d\n", queue_size(&rulesQueue)); pthread_mutex_lock(&mutex); myRule->ready= 1; pthread_cond_broadcast(&cond); pthread_mutex_unlock(&mutex); } return NULL; }
L::Integrator::Status L::RuleIntegrator::integrate ( Integrand &f, const Hypercube &h, Index maxEval, real reqAbsError, real reqRelError, EstErr &ee) { checkDimension(h, f); checkTerminationCriteria (maxEval, reqAbsError, reqRelError, false); std::auto_ptr<CubatureRule> rule (getRule(h.getDimension())); if (maxEval < rule->getNumPoints ()) { #ifdef HINTLIB_NO_EXCEPTIONS ee.set (0.0, 0.0); return ERROR; #else throw NoEvaluationsPossible (maxEval); #endif } ee.setNoErr (rule->eval(f, h)); return MAX_EVAL_REACHED; }
void RuleTreeAdapter::addToTree(const Root& rule, CEGUI::TreeItem* parent, bool addRecursive) { CEGUI::TreeItem* item = ColouredTreeItem::create(rule->getId()); item->toggleIsOpen(); if (!parent) { mTreeWidget.addItem(item); } else { parent->addItem(item); } if (addRecursive) { std::list<std::string> children; extractChildren(rule, children); for (auto& child : children) { const auto& childData = getRule(child); if (childData.isValid()) { addToTree(childData, item, addRecursive); } } } }
const strings_t Decision::getPredicates(string ruleName) const { return getRule()->find(ruleName)->second; }
int showRules( inStruct Sentries ) { int n, i, j; char ruleCondition[MAX_RULE_LENGTH]; char ruleAction[MAX_RULE_LENGTH]; char ruleRecovery[MAX_RULE_LENGTH]; char ruleHead[MAX_ACTION_SIZE]; char ruleBase[MAX_ACTION_SIZE]; char *actionArray[MAX_ACTION_IN_RULE]; char *recoveryArray[MAX_ACTION_IN_RULE]; char configDirEV[200]; char ruleSet[RULE_SET_DEF_LENGTH]; char oldRuleBase[MAX_ACTION_SIZE]; strcpy( ruleSet, "" ); strcpy( oldRuleBase, "" ); fprintf( stdout, "Content-type: text/html%c%c", 10, 10 ); fflush( stdout ); fprintf( stdout, "<HTML>\n<HEAD>\n<TITLE>iRODS Rule Administration</TITLE>\n</HEAD>\n<BODY bgcolor=#FFFFFF>\n" ); fprintf( stdout, "<CENTER> <B><FONT COLOR=#FF0000>iRODS Rule Base</FONT></B></CENTER>\n" ); fflush( stdout ); /* sprintf(configDirEV,"irodsConfigDir=/scratch/s1/sekar/irods/RODS/server/config"); sprintf(configDirEV,"irodsConfigDir=/misc/www/projects/srb-secure/cgi-bin"); putenv(configDirEV); */ for ( i = 0; i <= Sentries->m; i++ ) { if ( !strcmp( Sentries->entries[i].name, "ruleSet" ) ) { if ( strlen( Sentries->entries[i].val ) > 0 ) { if ( ruleSet[0] != '\0' ) { strcat( ruleSet, "," ); } rstrcat( ruleSet, Sentries->entries[i].val, 999 ); } } else if ( !strcmp( Sentries->entries[i].name, "configDir" ) ) { if ( strlen( Sentries->entries[i].val ) > 0 ) { snprintf( configDirEV, 199, "irodsConfigDir=%s", Sentries->entries[i].val ); } else { sprintf( configDirEV, "irodsConfigDir=%s", MY_SERVER_CONFIG_DIR ); } putenv( configDirEV ); } } if ( ruleSet[0] == '\0' ) { strcpy( ruleSet, "core" ); } fprintf( stdout, "<CENTER> <B><FONT COLOR=#0000FF>[%s]</FONT></B></CENTER>\n", ruleSet ); fflush( stdout ); initRuleStruct( NULL, ruleSet, "core", "core" ); fprintf( stdout, "<TABLE>\n" ); for ( j = 0 ; j < coreRuleStrct.MaxNumOfRules; j++ ) { getRule( j + 1000 , ruleBase, ruleHead, ruleCondition, ruleAction, ruleRecovery, MAX_RULE_LENGTH ); if ( strcmp( oldRuleBase, ruleBase ) ) { if ( strlen( oldRuleBase ) > 0 ) { fprintf( stdout, "<TR><TD COLSPAN=6><HR NOSHADE COLOR=#00FF00 SIZE=4></TD></TR>" ); } strcpy( oldRuleBase, ruleBase ); } n = getActionRecoveryList( ruleAction, ruleRecovery, actionArray, recoveryArray ); fprintf( stdout, "<TR><TD><BR> %i</TD><TD><BR> <FONT COLOR=#0000FF>ON</FONT></TD><TD COLSPAN=3><BR> <FONT COLOR=#FF0000>%s.</FONT><FONT COLOR=#0000FF>%s</FONT></TD></TR>\n", j, ruleBase, ruleHead ); if ( strlen( ruleCondition ) != 0 ) { fprintf( stdout, "<TR><TD></TD><TD></TD><TD VALIGN=TOP>IF </TD><TD COLSPAN=3 VALIGN=TOP><FONT COLOR=#FF0000>%s</FONT></TD></TR>\n", ruleCondition ); } for ( i = 0; i < n; i++ ) { if ( i == 0 ) fprintf( stdout, "<TR><TD></TD><TD></TD><TD VALIGN=TOP>DO </TD><TD VALIGN=TOP>%s</TD><TD NOWRAP> </TD><TD VALIGN=TOP>[%s]</TD></TR>\n", actionArray[i], recoveryArray[i] ); else fprintf( stdout, "<TR><TD></TD><TD></TD><TD VALIGN=TOP>AND </TD><TD VALIGN=TOP>%s</TD><TD NOWRAP> </TD><TD VALIGN=TOP>[%s]</TD></TR>\n", actionArray[i], recoveryArray[i] ); } } fprintf( stdout, "</TABLE>\n" ); fprintf( stdout, "</BODY>\n</HTML>\n" ); return 0; }
void Model::removeDuplicateTopLevelAnnotations() { unsigned int i, n; this->removeDuplicateAnnotations(); if (getNumFunctionDefinitions() > 0) { getListOfFunctionDefinitions()->removeDuplicateAnnotations(); for (i = 0; i < getNumFunctionDefinitions(); i++) { getFunctionDefinition(i)->removeDuplicateAnnotations(); } } if (getNumUnitDefinitions() > 0) { getListOfUnitDefinitions()->removeDuplicateAnnotations(); for (i = 0; i < getNumUnitDefinitions(); i++) { getUnitDefinition(i)->removeDuplicateAnnotations(); getUnitDefinition(i)->getListOfUnits()->removeDuplicateAnnotations(); for (n = 0; n < getUnitDefinition(i)->getNumUnits(); n++) { getUnitDefinition(i)->getUnit(n)->removeDuplicateAnnotations(); } } } if (getNumCompartmentTypes() > 0) { getListOfCompartmentTypes()->removeDuplicateAnnotations(); for (i = 0; i < getNumCompartmentTypes(); i++) { getCompartmentType(i)->removeDuplicateAnnotations(); } } if (getNumSpeciesTypes() > 0) { getListOfSpeciesTypes()->removeDuplicateAnnotations(); for (i = 0; i < getNumSpeciesTypes(); i++) { getSpeciesType(i)->removeDuplicateAnnotations(); } } if (getNumCompartments() > 0) { getListOfCompartments()->removeDuplicateAnnotations(); for (i = 0; i < getNumCompartments(); i++) { getCompartment(i)->removeDuplicateAnnotations(); } } if (getNumSpecies() > 0) { getListOfSpecies()->removeDuplicateAnnotations(); for (i = 0; i < getNumSpecies(); i++) { getSpecies(i)->removeDuplicateAnnotations(); } } if (getNumParameters() > 0) { getListOfParameters()->removeDuplicateAnnotations(); for (i = 0; i < getNumParameters(); i++) { getParameter(i)->removeDuplicateAnnotations(); } } if (getNumInitialAssignments() > 0) { getListOfInitialAssignments()->removeDuplicateAnnotations(); for (i = 0; i < getNumInitialAssignments(); i++) { getInitialAssignment(i)->removeDuplicateAnnotations(); } } if (getNumConstraints() > 0) { getListOfConstraints()->removeDuplicateAnnotations(); for (i = 0; i < getNumConstraints(); i++) { getConstraint(i)->removeDuplicateAnnotations(); } } if (getNumRules() > 0) { getListOfRules()->removeDuplicateAnnotations(); for (i = 0; i < getNumRules(); i++) { getRule(i)->removeDuplicateAnnotations(); } } if (getNumReactions() > 0) { getListOfReactions()->removeDuplicateAnnotations(); for (i = 0; i < getNumReactions(); i++) { Reaction * r = getReaction(i); r->removeDuplicateAnnotations(); if (r->getNumReactants() > 0) { r->getListOfReactants()->removeDuplicateAnnotations(); for (n = 0; n < r->getNumReactants(); n++) { r->getReactant(n)->removeDuplicateAnnotations(); } } if (r->getNumProducts() > 0) { r->getListOfProducts()->removeDuplicateAnnotations(); for (n = 0; n < r->getNumProducts(); n++) { r->getProduct(n)->removeDuplicateAnnotations(); } } if (r->getNumModifiers() > 0) { r->getListOfModifiers()->removeDuplicateAnnotations(); for (n = 0; n < r->getNumModifiers(); n++) { r->getModifier(n)->removeDuplicateAnnotations(); } } if (r->isSetKineticLaw()) { r->getKineticLaw()->removeDuplicateAnnotations(); if (r->getKineticLaw()->getNumParameters() > 0) { r->getKineticLaw()->getListOfParameters() ->removeDuplicateAnnotations(); for (n = 0; n < r->getKineticLaw()->getNumParameters(); n++) { r->getKineticLaw()->getParameter(n)->removeDuplicateAnnotations(); } } } } } if (getNumEvents() > 0) { getListOfEvents()->removeDuplicateAnnotations(); for (i = 0; i < getNumEvents(); i++) { getEvent(i)->removeDuplicateAnnotations(); if (getEvent(i)->getNumEventAssignments() > 0) { getEvent(i)->getListOfEventAssignments()->removeDuplicateAnnotations(); for (n = 0; n < getEvent(i)->getNumEventAssignments(); n++) { getEvent(i)->getEventAssignment(n)->removeDuplicateAnnotations(); } } } } }
void Model::removeSBOTerms(bool strict) { unsigned int n, i; if (strict == true) { unsetSBOTerm(); for (n = 0; n < getNumUnitDefinitions(); n++) { getUnitDefinition(n)->unsetSBOTerm(); for (i = 0; i < getUnitDefinition(n)->getNumUnits(); i++) { getUnitDefinition(n)->getUnit(i)->unsetSBOTerm(); } } for (n = 0; n < getNumCompartments(); n++) { getCompartment(n)->unsetSBOTerm(); } for (n = 0; n < getNumSpecies(); n++) { getSpecies(n)->unsetSBOTerm(); } for (n = 0; n < getNumParameters(); n++) { getParameter(n)->unsetSBOTerm(); } for (n = 0; n < getNumRules(); n++) { getRule(n)->unsetSBOTerm(); } for (n = 0; n < getNumReactions(); n++) { getReaction(n)->unsetSBOTerm(); for (i = 0; i < getReaction(n)->getNumReactants(); i++) { getReaction(n)->getReactant(i)->unsetSBOTerm(); if (getReaction(n)->getReactant(i)->isSetStoichiometryMath()) { getReaction(n)->getReactant(i)->getStoichiometryMath()->unsetSBOTerm(); } } for (i = 0; i < getReaction(n)->getNumProducts(); i++) { getReaction(n)->getProduct(i)->unsetSBOTerm(); if (getReaction(n)->getProduct(i)->isSetStoichiometryMath()) { getReaction(n)->getProduct(i)->getStoichiometryMath()->unsetSBOTerm(); } } for (i = 0; i < getReaction(n)->getNumModifiers(); i++) { getReaction(n)->getModifier(i)->unsetSBOTerm(); } if (getReaction(n)->isSetKineticLaw()) { getReaction(n)->getKineticLaw()->unsetSBOTerm(); } } for (n = 0; n < getNumFunctionDefinitions(); n++) { getFunctionDefinition(n)->unsetSBOTerm(); } for (n = 0; n < getNumEvents(); n++) { getEvent(n)->unsetSBOTerm(); for (i = 0; i < getEvent(n)->getNumEventAssignments(); i++) { getEvent(n)->getEventAssignment(i)->unsetSBOTerm(); } if (getEvent(n)->isSetTrigger()) { getEvent(n)->getTrigger()->unsetSBOTerm(); } if (getEvent(n)->isSetDelay()) { getEvent(n)->getDelay()->unsetSBOTerm(); } } } }
int main () { FILE* fp; char il[MLEN]; char ilc[MLEN]; char ribbon[MRIBBON]; //the ribbon of calculations. int rp = 0; // the ribbon phrase beggining int rn = 0; // ribbon new expressions starts here. int re = 0; // ribbon end. char rules[MRULES]; // list of rules applicable to the case. char * crule; int rsize; // rule size; int c; char * pname; int soffs; // input offset printf("Ssum\n"); fp = fopen ("defs", "r"); if (fp == NULL) { perror("Can't open file with definitions."); return -1; } c = 0; do { rules[c++] = fgetc(fp); if (rules[c-1] == '\n' ) rules[c-1] = rdel[0]; if (rules[c-1] == '\r' ) rules[c-1] = rdel[0]; } while ( (c < MRULES) && (rules[c-1] != EOF) ); rules[c-1] = 0; // clear EOL symbol printf("%d\n", strlen(rules)); printf("%s\n", rules ); memset((void*)il, 0, MLEN); //read input line. c = 0; do { il[c++] = getchar(); } while ( (c < MLEN) && (il[c-1] != '\n') ); il[c-1] = 0; //clear trailing spaces c--; while (il [c-1] == ' ' && c>0) il[--c] = 0; if (strlen (il) == 0) { printf("Empty input, skipping.\n"); return 0; } printf("%d\n", strlen(il)); printf("%s\n", il ); // normalize string and look for pattern in the definitions. normalize(il); // check if we have definition of the equation. soffs = checkExpr(il, rules); printf("Offset = %d\n", soffs); if ( soffs >=0 ) { rsize = getRule(soffs, rules); // extracting the rule from the list of rules crule = strtok( &rules[rsize], rdel ); //extract full rule string printf("crule: %s\n", crule); if (applyRule(il, crule) >=0 ) // apply rule type of 'X Y ==' or 'Y X =='. { printf("Answer: %s\n", crule); return 0; } }else { printf("Does not match any rule. Continue...\n"); } // now the main loop of pattern search and defs application memset(ribbon, 0, MRIBBON); strcpy (ribbon, il); re += strlen(il); ribbon[re++] = edel[0]; ribbon[re++] = '\n'; printf("%s\n", ribbon); strcpy(ilc, il); // copy input line. // getting names from rules list. pname = strtok (il," "); printf("Name: %s\n", pname); soffs = findDef(pname, rules); // looking for definition of name in the rules list. printf("Offset = %d\n", soffs); if ( soffs >=0 ) { rsize = getRule(soffs, rules); // extracting the rule from the list of rules crule = strtok( &rules[rsize], rdel ); //extract full rule string printf("Definition: %s\n", crule); // apply name printf("il before: %s\n", ilc); if ( applyName(ilc, crule, pname) >=0 ) { printf("Converted string: %s\n", crule); //add to ribbon addToRibbon(ribbon, crule); } }else { printf("Definition of name is not found. Please define the name and retry.\n"); return 0; } printf("Ribbon: %s\n", ribbon); // find all names in the definition. // find all operations in rules. close(fp); return 0; }
void Model::dealWithStoichiometry() { unsigned int idCount = 0; for (unsigned int i = 0; i < getNumReactions(); i++) { Reaction *r = getReaction(i); unsigned int j; for (j = 0; j < r->getNumReactants(); j++) { SpeciesReference *sr = r->getReactant(j); if (sr->isSetStoichiometry() == false) { if (sr->isSetId() == false) { createNoValueStoichMath(*this, *sr, idCount); idCount++; } else { // id is set it could be used by initialAssignment // used by rule // not used if (getInitialAssignment(sr->getId()) != NULL) { useStoichMath(*this, *sr, false); } else if (getRule(sr->getId()) != NULL) { //assignmentRule if (getRule(sr->getId())->getTypeCode() == SBML_ASSIGNMENT_RULE) { useStoichMath(*this, *sr, true); } else if (getRule(sr->getId())->getTypeCode() == SBML_RATE_RULE) { createParameterAsRateRule(*this, *sr, *(getRule(sr->getId())), idCount); idCount++; } } else { createNoValueStoichMath(*this, *sr, idCount); idCount++; } } } else { // stoichiometry is set if (sr->isSetId()) { // id is set it could be used by initialAssignment // used by rule // not used if (getInitialAssignment(sr->getId()) != NULL) { useStoichMath(*this, *sr, false); } else if (getRule(sr->getId()) != NULL) { //assignmentRule if (getRule(sr->getId())->getTypeCode() == SBML_ASSIGNMENT_RULE) { useStoichMath(*this, *sr, true); } else if (getRule(sr->getId())->getTypeCode() == SBML_RATE_RULE) { createParameterAsRateRule(*this, *sr, *(getRule(sr->getId())), idCount); idCount++; } } } // no id set - do not need to do anything } } for (j = 0; j < r->getNumProducts(); j++) { SpeciesReference *sr = r->getProduct(j); if (sr->isSetStoichiometry() == false) { if (sr->isSetId() == false) { createNoValueStoichMath(*this, *sr, idCount); idCount++; } else { // id is set it could be used by initialAssignment // used by rule // not used if (getInitialAssignment(sr->getId()) != NULL) { useStoichMath(*this, *sr, false); } else if (getRule(sr->getId()) != NULL) { //assignmentRule if (getRule(sr->getId())->getTypeCode() == SBML_ASSIGNMENT_RULE) { useStoichMath(*this, *sr, true); } else if (getRule(sr->getId())->getTypeCode() == SBML_RATE_RULE) { createParameterAsRateRule(*this, *sr, *(getRule(sr->getId())), idCount); idCount++; } } else { createNoValueStoichMath(*this, *sr, idCount); idCount++; } } } else { // stoichiometry is set if (sr->isSetId()) { // id is set it could be used by initialAssignment // used by rule // not used if (getInitialAssignment(sr->getId()) != NULL) { useStoichMath(*this, *sr, false); } else if (getRule(sr->getId()) != NULL) { //assignmentRule if (getRule(sr->getId())->getTypeCode() == SBML_ASSIGNMENT_RULE) { useStoichMath(*this, *sr, true); } else if (getRule(sr->getId())->getTypeCode() == SBML_RATE_RULE) { createParameterAsRateRule(*this, *sr, *(getRule(sr->getId())), idCount); idCount++; } } } // no id set - do not need to do anything } } } }
void CSV::parse () { Setting rule; getRule(rule); if (! rule.count()) { QString s(tr("Empty rule")); printStatusLogMessage(s); downloadComplete(); return; } QString ts = "Rule"; QString ts2, s; rule.getData(ts, ts2); if (! ts2.contains("Date:")) { QString ss(tr("Rule missing Date field")); printStatusLogMessage(ss); downloadComplete(); return; } ts = "Delimiter"; rule.getData(ts, s); if (! s.length()) { QString ss(tr("Delimiter not found")); printStatusLogMessage(ss); downloadComplete(); return; } setDelimiter(s); if (dateRange->isChecked()) { if (sdate->date() >= edate->date() || edate->date() <= sdate->date()) { QString ss = stringDone + " " + QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"); printStatusLogMessage(ss); downloadComplete(); return; } } QString type; ts = "Type"; rule.getData(ts, type); if (! type.length()) { QString ss(tr("Type not found")); printStatusLogMessage(ss); downloadComplete(); return; } ts = "Rule"; rule.getData(ts, ts2); QStringList fieldList = QStringList::split(",", ts2, FALSE); if (! fieldList.count()) { QString ss(tr("No rule found")); printStatusLogMessage(ss); downloadComplete(); return; } // get the directory path offset ts = "Directory"; QString directory; rule.getData(ts, directory); if (! directory.length()) { QString ss(tr("Directory not found")); printStatusLogMessage(ss); downloadComplete(); return; } // get the symbol filter ts = "SymbolFilter"; rule.getData(ts, ts2); QStringList symbolFilter = QStringList::split(",", ts2, FALSE); // check for time field and set the tickflag bool tickFlag = FALSE; ts = "Rule"; rule.getData(ts, ts2); if (ts2.contains("Time")) tickFlag = TRUE; else { if (ts2.contains("HHMMSS")) tickFlag = TRUE; } QStringList list; file->getFile(list); int loop; for (loop = 0; loop < (int) list.count(); loop++) { if (cancelFlag) break; QFile f(list[loop]); if (! f.open(QIODevice::ReadOnly)) continue; Q3TextStream stream(&f); QString symbol = symbolOveride; if (! symbol.length() && fieldList.findIndex("Symbol") == -1) { QStringList l = QStringList::split("/", list[loop], FALSE); symbol = l[l.count() - 1]; if (symbol.right(4).contains(".txt")) symbol.truncate(symbol.length() - 4); if (symbol.right(4).contains(".TXT")) symbol.truncate(symbol.length() - 4); while (symbol.contains("_")) symbol = symbol.remove(symbol.find("_", 0, TRUE), 1); } QString path; if (! type.compare("Stocks")) { QString tmp = "Stocks/" + directory; createDirectory(tmp, path); if (! path.length()) { QString ss(tr("CSVPlugin::Unable to create directory")); printStatusLogMessage(ss); downloadComplete(); f.close(); return; } } else { if (! type.compare("Futures")) { QString tmp = "Futures/" + directory; createDirectory(tmp, path); if (! path.length()) { QString ss(tr("CSVPlugin::Unable to create directory")); printStatusLogMessage(ss); downloadComplete(); f.close(); return; } } } path.append("/"); if (symbol.length()) { QString s = path; s.append(symbol); if (openDb(s, symbol, type, tickFlag)) continue; // QString ss = tr("Updating") + " " + symbol; // printStatusLogMessage(ss); progressBar->setProgress(loop, (int) list.count()); } int lineCount = 0; QFileInfo fi(f); QString fName = fi.fileName(); while(stream.atEnd() == 0) { QString ts = stream.readLine(); QStringList l = QStringList::split( '\n', substituteSeparator(ts, delim, '\n'), FALSE); lineCount++; if (l.count() != fieldList.count()) { QString ss = QString().sprintf( "%s - %s - %s: %s Number of fields in file (%i) != rule format (%i)", fName.latin1(), symbol.latin1(), tr("Line").latin1(), QString::number(lineCount).latin1(), l.count(), fieldList.count() ); printStatusLogMessage(ss); continue; } int fieldLoop; bool flag = FALSE; Setting r; for (fieldLoop = 0; fieldLoop < (int) fieldList.count(); fieldLoop++) { QString listItem = l[fieldLoop].stripWhiteSpace(); if (fieldList[fieldLoop].contains("Date:")) { QDate dt; getDate(fieldList[fieldLoop], listItem, r, dt); if (! dt.isValid()) { QString ss = QString().sprintf("%s - %s - %s: %s %s: %s", fName.latin1(), symbol.latin1(), tr("Line").latin1(), QString::number(lineCount).latin1(), tr("Bad date").latin1(), listItem.latin1() ); printStatusLogMessage(ss); flag = TRUE; break; } if (dateRange->isChecked()) { if (dt < sdate->date() || dt > edate->date()) { flag = TRUE; break; } } ts = "Date"; ts2 = dt.toString("yyyyMMdd"); r.setData(ts, ts2); continue; } if (! fieldList[fieldLoop].compare("Time")) { getTime(listItem, s); if (! s.length()) { QString ss = QString().sprintf("%s - %s - %s: %s %s: %s", fName.latin1(), symbol.latin1(), tr("Line").latin1(), QString::number(lineCount).latin1(), tr("Bad time").latin1(), listItem.latin1() ); printStatusLogMessage(ss); flag = TRUE; break; } ts = "Time"; r.setData(ts, s); continue; } if (! fieldList[fieldLoop].compare("Symbol")) { if (symbolFilter.count()) { if (symbolFilter.findIndex(listItem) == -1) { flag = TRUE; break; } } ts = "Symbol"; r.setData(ts, listItem); continue; } if (! fieldList[fieldLoop].compare("Name")) { ts = "Name"; r.setData(ts, listItem); continue; } if (! fieldList[fieldLoop].compare("Open") || ! fieldList[fieldLoop].compare("High") || ! fieldList[fieldLoop].compare("Low") || ! fieldList[fieldLoop].compare("Close")) { if (setTFloat(listItem, TRUE)) { QString ss = QString().sprintf("%s - %s - %s: %i %s: %s", fName.latin1(), symbol.latin1(), tr("Line").latin1(), lineCount, tr("Bad value").latin1(), tr(fieldList[fieldLoop]).latin1() ); printStatusLogMessage(ss); flag = TRUE; break; } ts = QString::number(tfloat); r.setData(fieldList[fieldLoop], ts); continue; } if (! fieldList[fieldLoop].compare("Volume") || ! fieldList[fieldLoop].compare("OI")) { if (setTFloat(listItem, FALSE)) { QString ss = QString().sprintf("%s - %s - %s: %s %s: %s", fName.latin1(), symbol.latin1(), tr("Line").latin1(), QString::number(lineCount).latin1(), tr("Bad value").latin1(), tr(fieldList[fieldLoop]).latin1() ); printStatusLogMessage(ss); flag = TRUE; break; } ts = QString::number(tfloat); r.setData(fieldList[fieldLoop], ts); continue; } } if (flag) continue; ts = "Date"; r.getData(ts, s); if (! s.length()) continue; ts = "Time"; r.getData(ts, ts2); if (ts2.length()) s.append(ts2); else s.append("000000"); Bar bar; if (bar.setDate(s)) { ts = "Date"; r.getData(ts, ts2); QString ss = tr("Bad date") + " " + ts2; printStatusLogMessage(ss); continue; } bar.setTickFlag(tickFlag); ts = "Open"; bar.setOpen(r.getDouble(ts)); ts = "High"; bar.setHigh(r.getDouble(ts)); ts = "Low"; bar.setLow(r.getDouble(ts)); ts = "Close"; bar.setClose(r.getDouble(ts)); ts = "Volume"; bar.setVolume(r.getDouble(ts)); ts = "OI"; bar.setOI(r.getInt(ts)); DBIndexItem item; if (! symbol.length()) { ts = "Symbol"; QString t; r.getData(ts, t); s = path; s.append(t); if (openDb(s, t, type, tickFlag)) continue; ts = "Name"; r.getData(ts, s); if (s.length()) { chartIndex->getIndexItem(t, item); item.setTitle(s); chartIndex->setIndexItem(t, item); } db.setBar(bar); ts = "Symbol"; r.getData(ts, ts2); // QString ss = tr("Updating") + " " + ts2; // printStatusLogMessage(ss); config.closePlugin(type); db.close(); emit signalWakeup(); } else { ts = "Name"; r.getData(ts, s); if (s.length()) { chartIndex->getIndexItem(symbol, item); item.setTitle(s); chartIndex->setIndexItem(symbol, item); } db.setBar(bar); emit signalWakeup(); } } db.close(); f.close(); } progressBar->setProgress((int) list.count(), (int) list.count()); downloadComplete(); if (cancelFlag) { cancelFlag = FALSE; printStatusLogMessage(stringCanceled); } else { QString ss = stringDone + " " + QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"); printStatusLogMessage(ss); } progressBar->reset(); }