def oswl_statistics_save(cluster_id, resource_type, data, version_info=None):
    dt = datetime.utcnow()
    rec = objects.OpenStackWorkloadStats.get_last_by(
        cluster_id, resource_type)
    cs = oswl_data_checksum(data)
    obj_data = {
        'updated_time': dt.time(),
        'resource_data': {'current': data},
        'resource_checksum': cs
    }
    if version_info is not None:
        obj_data['version_info'] = version_info

    if rec:
        if cs == rec.resource_checksum:
            return
        last_dict = rec.resource_data
        cur_dict = last_dict['current']
        if rec.created_date == dt.date():
            # update record
            obj_data['resource_data'].update({
                'added': _added(
                    dt.time(), cur_dict, data, last_dict['added']),
                'removed': _removed(
                    dt.time(), cur_dict, data, last_dict['removed']),
                'modified': _modified(
                    dt.time(), cur_dict, data, last_dict['modified'])
            })
            rec.is_sent = False
            objects.OpenStackWorkloadStats.update(rec, obj_data)
        else:
            # create new record
            obj_data.update({
                'cluster_id': cluster_id,
                'resource_type': resource_type,
                'created_date': dt.date()
            })
            obj_data['resource_data'].update({
                'added': _added(dt.time(), cur_dict, data, []),
                'removed': _removed(dt.time(), cur_dict, data, []),
                'modified': _modified(dt.time(), cur_dict, data, [])
            })
            objects.OpenStackWorkloadStats.create(obj_data)
    else:
        # it will be the first record
        obj_data.update({
            'cluster_id': cluster_id,
            'resource_type': resource_type,
            'created_date': dt.date()
        })
        obj_data['resource_data'].update({
            'added': _added(dt.time(), [], data, []),
            'removed': [],
            'modified': []
        })
        objects.OpenStackWorkloadStats.create(obj_data)
Save OSWL statistics data for given cluster and resource_type to DB.
dataset/ETHPy150Open openstack/fuel-web/nailgun/nailgun/statistics/oswl/saver.py/oswl_statistics_save