Computes which fraction of the time series is covered by the rules set.

@param seriesLength the time series length.
@param rules the grammar rules set.
@return a fraction covered by the rules.
484511
public static double getCoverAsFraction(int seriesLength, GrammarRules rules) {

    boolean[] coverageArray = new boolean[seriesLength];

    for (GrammarRuleRecord rule : rules) {
      if (0 == rule.ruleNumber()) {
        continue;
      }
      ArrayList<RuleInterval> arrPos = rule.getRuleIntervals();
      for (RuleInterval saxPos : arrPos) {
        int startPos = saxPos.getStart();
        int endPos = saxPos.getEnd();
        for (int j = startPos; j < endPos; j++) {
          coverageArray[j] = true;
        }
      }
    }

    int coverSum = 0;
    for (int i = 0; i < seriesLength; i++) {
      if (coverageArray[i]) {
        coverSum++;
      }
    }
    return (double) coverSum / (double) seriesLength;
  }
1123757
private void simplify(PatternRule rule, List<String> xmlLines) {
    List<Integer> linesToRemove = new ArrayList<>();
    String currentRuleId = null;
    Pattern pattern = Pattern.compile(".*id=[\"'](.*?)[\"'].*");
    String expectedSubId = rule.getSubId();
    int lineCount = 0;
    int subRuleCount = 0;
    int removedCount = 0;
    boolean inRuleGroup = false;
    String newRegex = null;
    boolean inAntiPattern = false;
    for (lineCount = 0; lineCount < xmlLines.size(); lineCount++) {
    //for (String xmlLine : xmlLines) {
      String xmlLine = xmlLines.get(lineCount);
      if (xmlLine.contains("<rulegroup")) {
        subRuleCount = 0;
        inRuleGroup = true;
      } else if (xmlLine.contains("</rulegroup>")) {
        subRuleCount = 0;
        inRuleGroup = false;
      } else if ((xmlLine.contains("<rule ")||xmlLine.contains("<rule>")) && inRuleGroup) {
        subRuleCount++;
      }
      Matcher m = pattern.matcher(xmlLine);
      if (m.matches()) {
        currentRuleId = m.group(1);
      }
      if (currentRuleId != null && !currentRuleId.equals(rule.getId())) {
        continue;
      }
      if (!inRuleGroup) {
        subRuleCount = 1;
      }
      if (!expectedSubId.equals("0") && !expectedSubId.equals(String.valueOf(subRuleCount))) {
        continue;
      }
      if (xmlLine.matches(".*<antipattern.*")) {
        inAntiPattern = true;
      }
      if (inAntiPattern) {
        continue;
      }
      if (xmlLine.matches(".*</antipattern.*")) {
        inAntiPattern = false;
        continue;
      }
      if (xmlLine.matches(".*<(token|pattern).*") || xmlLine.matches("\\s*</?marker>.*")) {
        linesToRemove.add(lineCount);
      }
      if (xmlLine.matches(".*</pattern.*")) {
        linesToRemove.add(lineCount);
        int lastTokenIndent = xmlLine.indexOf("<");
        newRegex = Strings.repeat(" ", lastTokenIndent) + getRegex(rule);
      }
    }
    Collections.reverse(linesToRemove); // start from end, as we need to remove items
    for (Integer s : linesToRemove) {
      xmlLines.remove(s.intValue());
      removedCount++;
    }
    if (removedCount == 0) {
      System.err.println("No line removed: " + rule + "[" + expectedSubId + "]");
    } else {
      xmlLines.add(linesToRemove.get(linesToRemove.size()-1), newRegex);
      touchedRulesCount++;
    }
  }
712288
private int determineSize(List<Match> t) {
        Match firstMatch = t.get(0);
        if (!(firstMatch.token instanceof SimpleToken)) {
            return t.size();
        }
        int charLength = 0;
        for (Match m : t) {
            SimpleToken token = (SimpleToken) m.token;
            charLength += token.getNormalized().length();
        }
        return charLength;
    }
302893
function (d, chart, series) {
            var returnWidth = 0;
            if (series.x.measure !== null && series.x.measure !== undefined) {
                returnWidth = Math.abs(series.x._scale((d.x < 0 ? d.x - d.width : d.x + d.width)) - series.x._scale(d.x));
            } else if (series.x._hasTimeField()) {
                returnWidth = series.x.floatingBarWidth;
            } else {
                returnWidth = d.width * ((chart._widthPixels() / series.x._max) - (dimple._helpers.xGap(chart, series) * 2)) - (dimple._helpers.xClusterGap(d, chart, series) * 2);
            }
            return returnWidth;
        }
106057
private static int minLen(String... patterns) {
    int minLen = patterns[0].length();
    for (String str : patterns) {
      if (str.length() < minLen) {
        minLen = str.length();
      }
    }
    return minLen;
  }
837975
public double stDev(double[] series) {
    double num0 = 0D;
    double sum = 0D;
    int count = 0;
    for (double tp : series) {
      num0 = num0 + tp * tp;
      sum = sum + tp;
      count += 1;
    }
    double len = ((Integer) count).doubleValue();
    return Math.sqrt((len * num0 - sum * sum) / (len * (len - 1)));
  }
427134
public int getLengthPrefix() {
    // Message ID
    int length = 1;
    // Number of rules
    length += 4;
    if (this.rules != null) {
      for (SubscriptionRequestRule rule : this.rules) {
        // Physical Layer
        ++length;
        // Transmitters
        length += 4 + rule.getNumTransmitters()
            * Transmitter.TRANSMITTER_ID_SIZE * 2;
        // Update interval
        length += 8;
      }

    }

    return length;
  }
1312790
public final void ruleEnumRule() throws RecognitionException {

        		int stackSize = keepStackSize();
        	
        try {
            // InternalXtext.g:1408:2: ( ( ( rule__EnumRule__Group__0 ) ) )
            // InternalXtext.g:1409:2: ( ( rule__EnumRule__Group__0 ) )
            {
            // InternalXtext.g:1409:2: ( ( rule__EnumRule__Group__0 ) )
            // InternalXtext.g:1410:3: ( rule__EnumRule__Group__0 )
            {
             before(grammarAccess.getEnumRuleAccess().getGroup()); 
            // InternalXtext.g:1411:3: ( rule__EnumRule__Group__0 )
            // InternalXtext.g:1411:4: rule__EnumRule__Group__0
            {
            pushFollow(FollowSets000.FOLLOW_2);
            rule__EnumRule__Group__0();

            state._fsp--;


            }

             after(grammarAccess.getEnumRuleAccess().getGroup()); 

            }


            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {

            	restoreStackSize(stackSize);

        }
        return ;
    }
1061051
@Override
    public boolean isBetween(Date start, Date end) {
        return rule.isBetween(start, end);
    }
812600
public static Integer computeGrammarSize(GrammarRules rules, Integer paaSize) {

    // The final grammar's size in BYTES
    //
    int res = 0;

    // The final size is the sum of the sizes of all rules
    //
    for (GrammarRuleRecord r : rules) {
      String ruleStr = r.getRuleString();
      String[] tokens = ruleStr.split("\\s+");
      int ruleSize = computeRuleSize(paaSize, tokens);
      res += ruleSize;
    }

    return res;
  }
1111972
NFRule findRule(double number) {
        // if this is a fraction rule set, use findFractionRuleSetRule()
        if (isFractionRuleSet) {
            return findFractionRuleSetRule(number);
        }

        if (Double.isNaN(number)) {
            NFRule rule = nonNumericalRules[NAN_RULE_INDEX];
            if (rule == null) {
                rule = owner.getDefaultNaNRule();
            }
            return rule;
        }

        // if the number is negative, return the negative number rule
        // (if there isn't a negative-number rule, we pretend it's a
        // positive number)
        if (number < 0) {
            if (nonNumericalRules[NEGATIVE_RULE_INDEX] != null) {
                return nonNumericalRules[NEGATIVE_RULE_INDEX];
            } else {
                number = -number;
            }
        }

        if (Double.isInfinite(number)) {
            NFRule rule = nonNumericalRules[INFINITY_RULE_INDEX];
            if (rule == null) {
                rule = owner.getDefaultInfinityRule();
            }
            return rule;
        }

        // if the number isn't an integer, we use one f the fraction rules...
        if (number != Math.floor(number)) {
            if (number < 1 && nonNumericalRules[PROPER_FRACTION_RULE_INDEX] != null) {
                // if the number is between 0 and 1, return the proper
                // fraction rule
                return nonNumericalRules[PROPER_FRACTION_RULE_INDEX];
            }
            else if (nonNumericalRules[IMPROPER_FRACTION_RULE_INDEX] != null) {
                // otherwise, return the improper fraction rule
                return nonNumericalRules[IMPROPER_FRACTION_RULE_INDEX];
            }
        }

        // if there's a master rule, use it to format the number
        if (nonNumericalRules[MASTER_RULE_INDEX] != null) {
            return nonNumericalRules[MASTER_RULE_INDEX];
        }
        else {
            // and if we haven't yet returned a rule, use findNormalRule()
            // to find the applicable rule
            return findNormalRule(Math.round(number));
        }
    }
897801
void setNonNumericalRule(NFRule rule) {
        long baseValue = rule.getBaseValue();
        if (baseValue == NFRule.NEGATIVE_NUMBER_RULE) {
            nonNumericalRules[NFRuleSet.NEGATIVE_RULE_INDEX] = rule;
        }
        else if (baseValue == NFRule.IMPROPER_FRACTION_RULE) {
            setBestFractionRule(NFRuleSet.IMPROPER_FRACTION_RULE_INDEX, rule, true);
        }
        else if (baseValue == NFRule.PROPER_FRACTION_RULE) {
            setBestFractionRule(NFRuleSet.PROPER_FRACTION_RULE_INDEX, rule, true);
        }
        else if (baseValue == NFRule.MASTER_RULE) {
            setBestFractionRule(NFRuleSet.MASTER_RULE_INDEX, rule, true);
        }
        else if (baseValue == NFRule.INFINITY_RULE) {
            nonNumericalRules[NFRuleSet.INFINITY_RULE_INDEX] = rule;
        }
        else if (baseValue == NFRule.NAN_RULE) {
            nonNumericalRules[NFRuleSet.NAN_RULE_INDEX] = rule;
        }
    }
1302236
public GrammarRules toGrammarRulesData() {

    GrammarRules res = new GrammarRules();

    GrammarRuleRecord r0 = new GrammarRuleRecord();
    r0.setRuleNumber(0);
    r0.setRuleString(this.r0String);
    r0.setExpandedRuleString(this.r0ExpandedString);
    r0.setOccurrences(new int[] { 0 });
    r0.setMeanLength(-1);
    r0.setMinMaxLength(new int[] { -1 });
    res.addRule(r0);

    for (RePairRule rule : theRules.values()) {
      // System.out.println("processing the rule " + rule.ruleNumber);
      GrammarRuleRecord rec = new GrammarRuleRecord();

      rec.setRuleNumber(rule.ruleNumber);
      rec.setRuleString(rule.toRuleString());
      rec.setExpandedRuleString(rule.expandedRuleString);
      rec.setRuleYield(countSpaces(rule.expandedRuleString));
      rec.setOccurrences(rule.getOccurrences());
      rec.setRuleIntervals(rule.getRuleIntervals());
      rec.setRuleLevel(rule.getLevel());
      rec.setMinMaxLength(rule.getLengths());
      rec.setMeanLength(mean(rule.getRuleIntervals()));

      res.addRule(rec);
    }

    // count the rule use
    for (GrammarRuleRecord r : res) {
      String str = r.getRuleString();
      String[] tokens = str.split("\\s+");
      for (String t : tokens) {
        if (t.startsWith("R")) {
          Integer ruleId = Integer.valueOf(t.substring(1));
          GrammarRuleRecord rr = res.get(ruleId);
          // System.out.print(rr.getRuleUseFrequency() + " ");
          int newFreq = rr.getRuleUseFrequency() + 1;
          rr.setRuleUseFrequency(newFreq);
          // System.out.println(rr.getRuleUseFrequency());
        }
      }
    }

    return res;
  }
63259
private int getSeriesSize(String series) {
        synchronized (dataStoreLock) {
            if (dataStore == null) {
                return 0;
            }
            if (seriesToBatch.containsKey(series)) {
                return (int) seriesToBatch.get(series).getDataSize();
            } else {
                return 0;
            }
        }
    }
324139
public String gaRuleAccessMethodName(final AbstractRule rule) {
    String _gaRuleIdentifyer = this.gaRuleIdentifyer(rule);
    String _plus = ("get" + _gaRuleIdentifyer);
    return (_plus + "Rule");
  }
459913
public final void ruleParserRule() throws RecognitionException {

        		int stackSize = keepStackSize();
        	
        try {
            // InternalXtext.g:241:2: ( ( ( rule__ParserRule__Group__0 ) ) )
            // InternalXtext.g:242:2: ( ( rule__ParserRule__Group__0 ) )
            {
            // InternalXtext.g:242:2: ( ( rule__ParserRule__Group__0 ) )
            // InternalXtext.g:243:3: ( rule__ParserRule__Group__0 )
            {
             before(grammarAccess.getParserRuleAccess().getGroup()); 
            // InternalXtext.g:244:3: ( rule__ParserRule__Group__0 )
            // InternalXtext.g:244:4: rule__ParserRule__Group__0
            {
            pushFollow(FollowSets000.FOLLOW_2);
            rule__ParserRule__Group__0();

            state._fsp--;


            }

             after(grammarAccess.getParserRuleAccess().getGroup()); 

            }


            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {

            	restoreStackSize(stackSize);

        }
        return ;
    }
809123
def computeA(self, j, timeSeries):
        
        seasonLength = self.get_parameter("seasonLength")
        A_j = 0
        for i in range(seasonLength):
            A_j += timeSeries[(seasonLength * (j)) + i][1]
        return A_j / seasonLength