import itertools


def _region_interval_to_dimensions(old_project_data):
    """
    From

    interval_definitions:
      - name: annual
        description: ''
        filename: annual_intervals.csv
    region_definitions:
      - name: national
        description: ''
        filename: uk_nations_shp/regions.shp
      - name: oxfordshire
        description: ''
        filename: oxfordshire/regions.geojson

    To

    dimensions:
      - name: annual
        description: ''
        elements: annual_intervals.csv
      - name: national
        description: ''
        elements: uk_nations_shp/regions.shp
      - name: oxfordshire
        description: ''
        elements: oxfordshire/regions.geojson
    """
    dimensions = []
    definitions = itertools.chain(
        old_project_data['interval_definitions'], 
        old_project_data['region_definitions']
    )
    for definition in definitions:
        dimensions.append({
            'name': definition['name'],
            'description': definition['description'],
            'elements': definition['filename']
        })
    
    old_project_data.pop('interval_definitions')
    old_project_data.pop('region_definitions')
    old_project_data['dimensions'] = dimensions

    return old_project_data