<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def import_load_timeseries(config_data, data_source, mv_grid_id=None, year=None):
 """ Import load time series Parameters config_data : dict Dictionary containing config data from config files. data_source : str Specify type of data source. Available data sources are * 'demandlib' Determine a load time series with the use of the demandlib. This calculates standard load profiles for 4 different sectors. mv_grid_id : :obj:`str` MV grid ID as used in oedb. Provide this if `data_source` is 'oedb'. Default: None. year : int Year for which to generate load time series. Provide this if `data_source` is 'demandlib'. Default: None. Returns ------- :pandas:`pandas.DataFrame<dataframe>` Load time series """


    def _import_load_timeseries_from_oedb(config_data, mv_grid_id):
        """
        Retrieve load time series from oedb

        Parameters
        ----------
        config_data : dict
            Dictionary containing config data from config files.

        Returns
        -------
        :pandas:`pandas.DataFrame<dataframe>`
            Load time series

        Notes
        ------
        This is currently not a valid option to retrieve load time series
        since time series in the oedb are not differentiated by sector. An
        issue concerning this has been created.

        """

        if config_data['versioned']['version'] == 'model_draft':
            orm_load_name = config_data['model_draft']['load_data']
            orm_load = model_draft.__getattribute__(orm_load_name)
            orm_load_areas_name = config_data['model_draft']['load_areas']
            orm_load_areas = model_draft.__getattribute__(orm_load_areas_name)
            orm_load_version = 1 == 1
        else:
            orm_load_name = config_data['versioned']['load_data']
            # orm_load = supply.__getattribute__(orm_load_name)
            # ToDo: remove workaround
            orm_load = model_draft.__getattribute__(orm_load_name)
            # orm_load_version = orm_load.version == config.data['versioned']['version']

            orm_load_areas_name = config_data['versioned']['load_areas']
            # orm_load_areas = supply.__getattribute__(orm_load_areas_name)
            # ToDo: remove workaround
            orm_load_areas = model_draft.__getattribute__(orm_load_areas_name)
            # orm_load_areas_version = orm_load.version == config.data['versioned']['version']

            orm_load_version = 1 == 1

        conn = connection(section=config_data['db_connection']['section'])
        Session = sessionmaker(bind=conn)
        session = Session()

        load_sqla = session.query(  # orm_load.id,
            orm_load.p_set,
            orm_load.q_set,
            orm_load_areas.subst_id). \
            join(orm_load_areas, orm_load.id == orm_load_areas.otg_id). \
            filter(orm_load_areas.subst_id == mv_grid_id). \
            filter(orm_load_version). \
            distinct()

        load = pd.read_sql_query(load_sqla.statement,
                                 session.bind,
                                 index_col='subst_id')
        return load

    def _load_timeseries_demandlib(config_data, year):
        """
        Get normalized sectoral load time series

        Time series are normalized to 1 kWh consumption per year

        Parameters
        ----------
        config_data : dict
            Dictionary containing config data from config files.
        year : int
            Year for which to generate load time series.

        Returns
        -------
        :pandas:`pandas.DataFrame<dataframe>`
            Load time series

        """

        sectoral_consumption = {'h0': 1, 'g0': 1, 'i0': 1, 'l0': 1}

        cal = Germany()
        holidays = dict(cal.holidays(year))

        e_slp = bdew.ElecSlp(year, holidays=holidays)

        # multiply given annual demand with timeseries
        elec_demand = e_slp.get_profile(sectoral_consumption)

        # Add the slp for the industrial group
        ilp = profiles.IndustrialLoadProfile(e_slp.date_time_index,
                                             holidays=holidays)

        # Beginning and end of workday, weekdays and weekend days, and scaling
        # factors by default
        elec_demand['i0'] = ilp.simple_profile(
            sectoral_consumption['i0'],
            am=datetime.time(config_data['demandlib']['day_start'].hour,
                             config_data['demandlib']['day_start'].minute, 0),
            pm=datetime.time(config_data['demandlib']['day_end'].hour,
                             config_data['demandlib']['day_end'].minute, 0),
            profile_factors=
            {'week': {'day': config_data['demandlib']['week_day'],
                      'night': config_data['demandlib']['week_night']},
             'weekend': {'day': config_data['demandlib']['weekend_day'],
                         'night': config_data['demandlib']['weekend_night']}})

        # Resample 15-minute values to hourly values and sum across sectors
        elec_demand = elec_demand.resample('H').mean()

        return elec_demand

    if data_source == 'oedb':
        load = _import_load_timeseries_from_oedb(config_data, mv_grid_id)
    elif data_source == 'demandlib':
        load = _load_timeseries_demandlib(config_data, year)
        load.rename(columns={'g0': 'retail', 'h0': 'residential',
                             'l0': 'agricultural', 'i0': 'industrial'},
                    inplace=True)
    return load