// Calculates the integral (history) component of the trust value
7903
func (tm *TrustMetric) calcHistoryValue() float64 {
	var hv float64

	for i := 0; i < tm.numIntervals; i++ {
		hv += tm.fadedMemoryValue(i) * tm.historyWeights[i]
	}

	return hv / tm.historyWeightSum
}
369254
func GetPvtdataStoreCollElgProcDbBatchesInterval() int {
	collElgProcDbBatchesInterval := viper.GetInt(confCollElgProcDbBatchesInterval.Name)
	if collElgProcDbBatchesInterval <= 0 {
		collElgProcDbBatchesInterval = confCollElgProcDbBatchesInterval.DefaultVal
	}
	return collElgProcDbBatchesInterval
}
1223491
func (rs *ReferenceRiskService) Calculate(patientID string, fhirEndpointURL string, basisPieURL string) error {
	// Get and post the query to retrieve all of the data needed by the risk service plugins
	queryURL, err := rs.getRequiredDataQueryURL(patientID, fhirEndpointURL)
	if err != nil {
		return err
	}
	response, err := http.Get(queryURL)
	if err != nil {
		return err
	}
	defer response.Body.Close()
	bundle := &models.Bundle{}
	if err = json.NewDecoder(response.Body).Decode(bundle); err != nil {
		return err
	}

	// Convert the data bundle and significant birthdays into an EventStream
	es, err := BundleToEventStream(bundle)
	if err != nil {
		return err
	}

	// Now do the calculations for each plugin
	for _, p := range rs.plugins {
		if len(p.Config().Method.Coding) == 0 {
			return errors.New("Risk Assessment Plugins MUST provide a method with a coding")
		}

		// Copy the event stream since we'll add significant birthday events based on plugin config
		esClone := es.Clone()
		addSignificantBirthdayEvents(esClone, p.Config().SignificantBirthdays)

		// Calculate the results
		results, err := p.Calculate(esClone, fhirEndpointURL)
		if err != nil {
			if _, ok := err.(plugin.NotApplicableError); ok {
				UpdateRiskAssessmentsAndPies(fhirEndpointURL, patientID, results, rs.db.C("pies"), basisPieURL, p.Config(), true)
				continue
			} else {
				return err
			}
		}
		results = sortAndConsolidate(results)

		UpdateRiskAssessmentsAndPies(fhirEndpointURL, patientID, results, rs.db.C("pies"), basisPieURL, p.Config(), false)
	}

	return nil
}
97652
func getRandIntValue(dataVal []string) int {
	if !intDataCheck(dataVal) {
		return 0
	}
	return data.IntData[dataVal[0]][dataVal[1]][rand.Intn(len(data.IntData[dataVal[0]][dataVal[1]]))]
}
1273130
func (s *DynamicBanScore) int(t time.Time) uint32 {
	dt := t.Unix() - s.lastUnix
	if s.transient < 1 || dt < 0 || Lifetime < dt {
		return s.persistent
	}
	return s.persistent + uint32(s.transient*decayFactor(dt))
}
778135
func builtinTime(args []types.Datum, ctx context.Context) (d types.Datum, err error) {
	if args[0].IsNull() {
		return
	}

	str, err := args[0].ToString()
	if err != nil {
		return d, errors.Trace(err)
	}
	idx := strings.Index(str, ".")
	fsp := 0
	if idx != -1 {
		fsp = len(str) - idx - 1
	}
	sc := ctx.GetSessionVars().StmtCtx
	fspD := types.NewIntDatum(int64(fsp))
	if fsp, err = checkFsp(sc, fspD); err != nil {
		return d, errors.Trace(err)
	}

	return convertToDuration(sc, args[0], fsp)
}
564445
func (m *missionControl) ResetHistory() {
	m.Lock()
	m.failedEdges = make(map[EdgeLocator]time.Time)
	m.failedVertexes = make(map[route.Vertex]time.Time)
	m.Unlock()
}
1013624
func WithTrust(cmd *icmd.Cmd) {
	env := append(os.Environ(),
		"DOCKER_CONTENT_TRUST=1",
	)
	cmd.Env = append(cmd.Env, env...)
}
953581
func (c *Config) MaxStatusHistorySizeMB() uint {
	// Value has already been validated.
	val, _ := utils.ParseSize(c.mustString(MaxStatusHistorySize))
	return uint(val)
}
861432
func builtinTimestampDiff(args []types.Datum, ctx context.Context) (d types.Datum, err error) {
	sc := ctx.GetSessionVars().StmtCtx
	t1, err := convertDatumToTime(sc, args[1])
	if err != nil {
		return d, errorOrWarning(err, ctx)
	}
	t2, err := convertDatumToTime(sc, args[2])
	if err != nil {
		return d, errorOrWarning(err, ctx)
	}
	if t1.InvalidZero() || t2.InvalidZero() {
		return d, errorOrWarning(types.ErrInvalidTimeFormat, ctx)
	}

	v := types.TimestampDiff(args[0].GetString(), t1, t2)
	d.SetInt64(v)
	return
}
469346
func GetHistory(ctx sessionctx.Context) *StmtHistory {
	hist, ok := ctx.GetSessionVars().TxnCtx.History.(*StmtHistory)
	if ok {
		return hist
	}
	hist = new(StmtHistory)
	ctx.GetSessionVars().TxnCtx.History = hist
	return hist
}
711761
func (tm *TrustMetric) HistoryJSON() MetricHistoryJSON {
	tm.mtx.Lock()
	defer tm.mtx.Unlock()

	return MetricHistoryJSON{
		NumIntervals: tm.numIntervals,
		History:      tm.history,
	}
}
472391
func NewHistoryOfSize(filename string, size int) (*history, error) {
	if size <= 0 {
		return nil, errors.New("wrong history size: " + strconv.Itoa(size))
	}

	return _baseHistory(filename, size)
}
1059391
func (r *Session) GetRemoteHistory(imgID, registry string) ([]string, error) {
	res, err := r.client.Get(registry + "images/" + imgID + "/ancestry")
	if err != nil {
		return nil, err
	}
	defer res.Body.Close()
	if res.StatusCode != 200 {
		if res.StatusCode == 401 {
			return nil, errcode.ErrorCodeUnauthorized.WithArgs()
		}
		return nil, newJSONError(fmt.Sprintf("Server error: %d trying to fetch remote history for %s", res.StatusCode, imgID), res)
	}

	var history []string
	if err := json.NewDecoder(res.Body).Decode(&history); err != nil {
		return nil, fmt.Errorf("Error while reading the http response: %v", err)
	}

	logrus.Debugf("Ancestry: %v", history)
	return history, nil
}
1182505
func (m *MonitorValues) FlattenInternetInValue() ([]FlatMonitorValue, error) {
	return m.flattenValue(func(v *MonitorValue) *float64 { return v.In })
}
398088
func (pi *PromisedID) Value() (int, error) {
	if *pi == -1 {
		return -1, errors.New("value has not been computed yet")
	}
	return (int)(*pi), nil
}
1162362
func (tm *TrustMetric) calcTrustValue() float64 {
	weightedP := tm.proportionalWeight * tm.proportionalValue()
	weightedI := tm.integralWeight * tm.historyValue
	weightedD := tm.weightedDerivative()

	tv := weightedP + weightedI + weightedD
	// Do not return a negative value.
	if tv < 0 {
		tv = 0
	}
	return tv
}