def process(filenames: List[str],
            signal_names: List[str],
            wip_signal,
            geo_resolutions: List[str],
            export_dir: str):
    """Create and exports signals corresponding both single day and averaged over the previous week.

    Parameters
    ----------
    current_filename: List[str]
        paths to files holding data.
        The first entry of the list should correspond to the target date while
        the remaining entries should correspond to the dates from each day in
        the week preceding the target date.
    signal_names: List[str]
        signal names to be processed for a single date.
        A second version of each such signal named {SIGNAL}_7d_avg will be
        created averaging {SIGNAL} over the past 7 days.
    wip_signal : List[str] or bool
        a list of wip signals: [], OR
        all signals in the registry: True OR
        only signals that have never been published: False
    geo_resolutions: List[str]
        List of geo resolutions to export the data.
    export_dir
        path where the output files are saved.
    Returns
    -------
    None.  For each (signal, resolution) pair, one file is written for the
    single date values to {export_dir}/{date}_{resolution}_{signal}.csv and
    one for the data averaged over the previous week to
    {export_dir}/{date}_{resolution}_{signal}_7d_avg.csv.
    """
    past_week = []
    for fname in filenames:
        if os.path.exists(fname):
            past_week.append(pd.read_csv(fname))

    # First process the current file alone...
    process_window(past_week[:1],
                   add_prefix(signal_names, wip_signal, 'wip_'),
                   geo_resolutions,
                   export_dir)
    # ...then as part of the whole window.
    process_window(past_week,
                   add_prefix(add_suffix(signal_names, '_7dav'),
                              wip_signal,
                              'wip_'),
                   geo_resolutions,
                   export_dir)
 def test_add_prefix_to_non_public(self, metadata):
     """Tests that `add_prefix()` derives work-in-progress names for non-public signals."""
     metadata.return_value = PUBLIC_SIGNALS_FRAME
     assert add_prefix(["sig0", "sig1"], False,
                       prefix="wip_") == ["wip_sig0", "sig1"]
 def test_invalid_prefix_input(self):
     """Tests that `add_prefix()` raises a ValueError when invalid input is given."""
     with pytest.raises(ValueError):
         add_prefix(None, None)
 def test_add_prefix_to_specified(self):
     """Tests that `add_prefix()` derives work-in-progress names for specified signals."""
     assert add_prefix(["sig1", "sig2", "sig3"], ["sig2"], prefix="wip_") ==\
         ["sig1", "wip_sig2", "sig3"]
 def test_add_prefix_to_all(self):
     """Tests that `add_prefix()` derives work-in-progress names for all input signals."""
     assert add_prefix(["sig1", "sig3"], True,
                       prefix="wip_") == ["wip_sig1", "wip_sig3"]
Beispiel #6
0
 def test_add_no_prefix(self):
     """Tests that `add_prefix()` doesn't affect signals if `wip_signals` is False or ''."""
     assert add_prefix(["sig0", "sig1"], False, prefix="wip_") == ["sig0", "sig1"]
     assert add_prefix(["sig0", "sig1"], "", prefix="wip_") == ["sig0", "sig1"]