Compares two models

Compares two models#

In this example we show how to use polaris testing capabilities for comparing two different networks

import shutil
from pathlib import Path

from polaris import Polaris
from polaris.utils.testing.model_comparison.compare_databases import compare_databases


# Let's copy the model we have available for testing
model_path1 = Path("/tmp/Grid")
model_path2 = Path("/tmp/Grid_model_comparison")
if model_path2.exists():
    shutil.rmtree(model_path2)
shutil.copytree("/tmp/Grid", "/tmp/Grid_model_comparison")

project1 = Polaris.from_dir(model_path1)
project2 = Polaris.from_dir(model_path2)

We can compare two identical supply files We must provide the path to the supply databases

report = compare_databases(project1.supply_file, project2.supply_file)

for record in report:
    print(record)
**No dropped tables**

**No new tables**

**Tables with no changes**:

about_model, area_type, connection, county_skims, editing_table, electricity_grid_transmission, electricity_provider, electricity_provider_pricing, ev_charging_station_plug_types, ev_charging_station_plugs, ev_charging_station_pricing, ev_charging_station_service_bays, ev_charging_stations, land_use, link, link_overrides, link_type, location, location_links, location_parking, micromobility_agencies, micromobility_docks, micromobility_operators, migrations, node, parking, phasing, phasing_nested_records, pocket, road_connectors, roadsideunit, sanity_check, settings, sign, signal, signal_nested_records, timing, timing_nested_records, toll_pricing, traffic_incident, transit_agencies, transit_bike, transit_fare_attributes, transit_fare_rules, transit_links, transit_modes, transit_pattern_links, transit_pattern_mapping, transit_patterns, transit_routes, transit_stops, transit_trips, transit_trips_schedule, transit_walk, transit_zones, turn_overrides, use_code, zone

Or we can do something drastic like remove all transit data and then compare them

project2.network.transit.purge()

report = compare_databases(project1.supply_file, project2.supply_file)

for record in report:
    print(record)

project1.close()
project2.close()
**No dropped tables**

**No new tables**

**Tables with no changes**:

about_model, area_type, connection, county_skims, electricity_grid_transmission, electricity_provider, electricity_provider_pricing, ev_charging_station_plug_types, ev_charging_station_plugs, ev_charging_station_pricing, ev_charging_station_service_bays, ev_charging_stations, land_use, link, link_overrides, link_type, location, location_links, location_parking, micromobility_agencies, micromobility_docks, micromobility_operators, migrations, node, parking, phasing, phasing_nested_records, pocket, road_connectors, roadsideunit, sanity_check, settings, sign, signal, signal_nested_records, timing, timing_nested_records, toll_pricing, traffic_incident, transit_modes, transit_pattern_mapping, turn_overrides, use_code, zone



**Tables with changes**:

editing_table:

     * 954 records added to table

transit_agencies:

     * 6 records deleted from table

transit_bike:

     * 477 records deleted from table

transit_fare_attributes:

     * 6 records deleted from table

transit_fare_rules:

     * 18 records deleted from table

transit_links:

     * 44 records deleted from table

transit_pattern_links:

     * 44 records deleted from table

transit_patterns:

     * 13 records deleted from table

transit_routes:

     * 5 records deleted from table

transit_stops:

     * 34 records deleted from table

transit_trips:

     * 3,731 records deleted from table

transit_trips_schedule:

     * 16,359 records deleted from table

transit_walk:

     * 477 records deleted from table

transit_zones:

     * 6 records deleted from table

Total running time of the script: (0 minutes 1.244 seconds)

Gallery generated by Sphinx-Gallery