• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

blue-marble / gridpath / 24158835669

08 Apr 2026 09:08PM UTC coverage: 88.927% (-0.03%) from 88.956%
24158835669

Pull #1351

github

web-flow
Merge a41ad8303 into ad380fcdb
Pull Request #1351: RA Toolkit updates

110 of 132 new or added lines in 12 files covered. (83.33%)

69 existing lines in 9 files now uncovered.

27497 of 30921 relevant lines covered (88.93%)

0.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

26.67
/data_toolkit/project/create_sync_gen_input_csvs_common.py
1
# Copyright 2016-2023 Blue Marble Analytics LLC.
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
6
#
7
#     http://www.apache.org/licenses/LICENSE-2.0
8
#
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
# See the License for the specific language governing permissions and
13
# limitations under the License.
14

15
import os.path
1✔
16
import pandas as pd
1✔
17

18
from db.common_functions import connect_to_database
1✔
19

20

21
def create_profile_csvs(
1✔
22
    db_path,
23
    project,
24
    profile_scenario_id,
25
    profile_scenario_name,
26
    stage_id,
27
    output_directory,
28
    overwrite,
29
    param_name,
30
    raw_data_table_name,
31
    raw_data_units_table_name,
32
    no_hydro_iteration=False,
33
):
34
    conn = connect_to_database(db_path=db_path)
×
35

36
    # Get the weighted cap factor for each of the project's constituent units,
37
    # get the UNION of these tables, and then find the project cap factor
38
    # with SUM and GROUP BY
39
    hydro_iter_sql = "" if no_hydro_iteration else "0 AS hydro_iteration,"
×
40
    query = f"""
×
41
        SELECT year AS weather_iteration, 
42
        {hydro_iter_sql}
43
        {stage_id} AS stage_id, 
44
        hour_of_year as timepoint, sum(weighted_{param_name}) as {param_name}
45
            FROM (
46
            SELECT year, month, day_of_month, hour_of_day, unit, 
47
            project, unit_weight, value, unit_weight * value as 
48
            weighted_{param_name},
49
                (CAST(
50
                    strftime('%j',
51
                        year || '-' || 
52
                        CASE
53
                        WHEN month > 9 THEN month
54
                        ELSE '0' || month END
55
                        || '-' || 
56
                        CASE
57
                        WHEN day_of_month > 9 THEN day_of_month
58
                        ELSE '0' || day_of_month END
59
                        ) AS DECIMAL
60
                    ) - 1) * 24 + hour_of_day AS hour_of_year
61
            FROM {raw_data_table_name}
62
            JOIN {raw_data_units_table_name}
63
            USING (unit)
64
            WHERE project = '{project}'
65
            )
66
        GROUP BY year, hour_of_year
67
        ORDER BY year, hour_of_year
68
    """
69

70
    # Put into a dataframe and add to file
71
    df = pd.read_sql(query, con=conn)
×
72

73
    filename = os.path.join(
×
74
        output_directory,
75
        f"{project}-{profile_scenario_id}-" f"{profile_scenario_name}.csv",
76
    )
77

78
    if overwrite:
×
79
        mode = "w"
×
80
    else:
81
        mode = "a"
×
82

UNCOV
83
    write_header = not os.path.exists(filename)
×
84

UNCOV
85
    df.to_csv(
×
86
        filename,
87
        mode=mode,
88
        header=True if mode == "w" or write_header else False,
89
        index=False,
90
    )
91

UNCOV
92
    conn.close()
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc