Beispiel #1
0
def main():
    """Create analysis with crude data in the analysis collection."""

    for cow in mongo.cows():
        type_ = TYPES['identity']
        label = LABELS['prods']
        parents = []
        settings = {'cow': cow}

        if mongo.is_analysis(type_, label, parents, settings):
            print('The document must be unique: {}'.format(cow))
        else:
            mongo.db.analysis.insert_one({
                'type': type_,
                'label': label,
                'parents': parents,
                'settings': settings,
                'data': mongo.prods(cow),
            })
Beispiel #2
0
def main():
    """Complete the crudedata collection with missing dates."""

    for cow in mongo.cows():
        print("Completing cow {}...".format(cow))

        dates = mongo.dates(cow)
        missing = get_missing_dates(dates)

        if missing:
            for lact in reversed(mongo.lacts(cow)):
                # The last date and day in database for this lactation
                last_date, last_day = get_last(cow, lact)

                # We start at the last day of the lactation then add the
                # missing lines till we reach the first day of the lactation
                while last_day > 1:
                    last_day -= 1
                    last_date -= dt.timedelta(1)

                    if last_date in missing:
                        # If day = 1, we'll have a problem of unique key in
                        # the second loop
                        missing.remove(last_date)

                        insert(cow, last_date, lact, last_day)

                last_date, last_day = get_last(cow, lact)

                # We start at the last day of the lactation then add the
                # missing lines till we reach the next lactation or the end of
                # the data if this lactation is the last one
                while last_date + dt.timedelta(1) in missing:
                    last_day += 1
                    last_date += dt.timedelta(1)

                    insert(cow, last_date, lact, last_day)
Beispiel #3
0
def main():
    """Complete the crudedata collection with missing dates."""

    for cow in mongo.cows():
        print("Completing cow {}...".format(cow))

        dates = mongo.dates(cow)
        missing = get_missing_dates(dates)

        if missing:
            for lact in reversed(mongo.lacts(cow)):
                # The last date and day in database for this lactation
                last_date, last_day = get_last(cow, lact)

                # We start at the last day of the lactation then add the
                # missing lines till we reach the first day of the lactation
                while last_day > 1:
                    last_day -= 1
                    last_date -= dt.timedelta(1)

                    if last_date in missing:
                        # If day = 1, we'll have a problem of unique key in
                        # the second loop
                        missing.remove(last_date)

                        insert(cow, last_date, lact, last_day)

                last_date, last_day = get_last(cow, lact)

                # We start at the last day of the lactation then add the
                # missing lines till we reach the next lactation or the end of
                # the data if this lactation is the last one
                while last_date + dt.timedelta(1) in missing:
                    last_day += 1
                    last_date += dt.timedelta(1)

                    insert(cow, last_date, lact, last_day)
Beispiel #4
0
def main():
    """Launch the analysis."""

    for cow in mongo.cows():
        # Crude
        dta = mongo.identity(cow, LABELS['prods'])
        _id = dta['_id']

        views.Crude(_id).render()

        acf_ids = analysis.acf({
            LABELS['values']: {},
            LABELS['confint']: {'alpha': 0.05},
        }, {
            'data': _id,
        })

        views.ACF('production', 'ACF', [acf_ids]).render()

        pacf_ids = analysis.pacf({
            LABELS['values']: {},
            LABELS['confint']: {'alpha': 0.05},
        }, {
            'data': _id,
        })

        views.PACF('production', 'PACF', [pacf_ids]).render()

        # Smoothing
        smooth_ids = []
        steps = [7, 30]

        for step in steps:
            id_ = smoothing(_id, step)[LABELS['values']]
            smooth_ids.append(id_)

            # R: TODO
            if step == 7:
                sdta = mongo.data(id_)

        views.Smoothing('production', 'Smoothed production', 
                        smooth_ids).render()

        # Differencing
        diff_ids = []
        acf_ids = []
        pacf_ids = []
        degrees = [1]

        for degree in degrees:
            id_ = differencing(_id, degree)[LABELS['values']]
            diff_ids.append(id_)

            acf_ids.append(analysis.acf({
                LABELS['values']: {},
                LABELS['confint']: {'alpha': 0.05},
            }, {
                'data': id_,
            }))

            pacf_ids.append(analysis.pacf({
                LABELS['values']: {},
                LABELS['confint']: {'alpha': 0.05},
            }, {
                'data': id_,
            }))


        views.Differencing('production', 'Differenced production', 
                           diff_ids).render()

        views.ACF(join('production', 'differenced'), 'ACF', acf_ids).render()

        views.PACF(join('production', 'differenced'), 'PACF', pacf_ids).render()
Beispiel #5
0
def main():
    """Launch the analysis."""

    for cow in mongo.cows():
        # Crude
        dta = mongo.identity(cow, LABELS['prods'])
        _id = dta['_id']

        views.Crude(_id).render()

        acf_ids = analysis.acf(
            {
                LABELS['values']: {},
                LABELS['confint']: {
                    'alpha': 0.05
                },
            }, {
                'data': _id,
            })

        views.ACF('production', 'ACF', [acf_ids]).render()

        pacf_ids = analysis.pacf(
            {
                LABELS['values']: {},
                LABELS['confint']: {
                    'alpha': 0.05
                },
            }, {
                'data': _id,
            })

        views.PACF('production', 'PACF', [pacf_ids]).render()

        # Smoothing
        smooth_ids = []
        steps = [7, 30]

        for step in steps:
            id_ = smoothing(_id, step)[LABELS['values']]
            smooth_ids.append(id_)

            # R: TODO
            if step == 7:
                sdta = mongo.data(id_)

        views.Smoothing('production', 'Smoothed production',
                        smooth_ids).render()

        # Differencing
        diff_ids = []
        acf_ids = []
        pacf_ids = []
        degrees = [1]

        for degree in degrees:
            id_ = differencing(_id, degree)[LABELS['values']]
            diff_ids.append(id_)

            acf_ids.append(
                analysis.acf(
                    {
                        LABELS['values']: {},
                        LABELS['confint']: {
                            'alpha': 0.05
                        },
                    }, {
                        'data': id_,
                    }))

            pacf_ids.append(
                analysis.pacf(
                    {
                        LABELS['values']: {},
                        LABELS['confint']: {
                            'alpha': 0.05
                        },
                    }, {
                        'data': id_,
                    }))

        views.Differencing('production', 'Differenced production',
                           diff_ids).render()

        views.ACF(join('production', 'differenced'), 'ACF', acf_ids).render()

        views.PACF(join('production', 'differenced'), 'PACF',
                   pacf_ids).render()