database/migrations/0061_historical_data_qty_stats.py
def calculate_data_quantity_stats(participant: Participant):
        """ Update the SummaryStatisticDaily  stats for a participant, using ChunkRegistry data """
        study_timezone = gettz(participant.study.timezone_name)
        query = ChunkRegistry.objects.filter(participant=participant)

        daily_data_quantities = defaultdict(lambda: defaultdict(int))
        # Construct a dict formatted like this: dict[date][data_type] = total_bytes
        for chunkregistry in query.values_list('time_bin', 'data_type', 'file_size'):
            day = chunkregistry[0].astimezone(study_timezone).date()
            filesize = chunkregistry[2]
            if filesize is None:
                filesize = 0
            daily_data_quantities[day][chunkregistry[1]] += filesize
        # For each date, create a DataQuantity object
        for day, day_data in daily_data_quantities.items():
            data_quantity = {
                "participant": participant,
                "date": day,
                "defaults": {}
            }
            for data_type, total_bytes in day_data.items():
                if data_type in ALL_DATA_STREAMS:
                    data_quantity["defaults"][f"{data_type}_bytes"] = total_bytes
            SummaryStatisticDaily.objects.update_or_create(**data_quantity)
 Update the SummaryStatisticDaily  stats for a participant, using ChunkRegistry data 
Update the SummaryStatisticDaily  stats for a participant, using ChunkRegistry data
Update the SummaryStatisticDaily stats for a participant using ChunkRegistry data
def calculate_data_quantity_stats(participant: Participant):
        study_timezone = gettz(participant.study.timezone_name)
        query = ChunkRegistry.objects.filter(participant=participant)
        daily_data_quantities = defaultdict(lambda: defaultdict(int))
        for chunkregistry in query.values_list('time_bin', 'data_type', 'file_size'):
            day = chunkregistry[0].astimezone(study_timezone).date()
            filesize = chunkregistry[2]
            if filesize is None:
                filesize = 0
            daily_data_quantities[day][chunkregistry[1]] += filesize
        for day, day_data in daily_data_quantities.items():
            data_quantity = {
                "participant": participant,
                "date": day,
                "defaults": {}
            }
            for data_type, total_bytes in day_data.items():
                if data_type in ALL_DATA_STREAMS:
                    data_quantity["defaults"][f"{data_type}_bytes"] = total_bytes
            SummaryStatisticDaily.objects.update_or_create(**data_quantity)
def calculate_data_quantity_stats ( participant : Participant ) : study_timezone = gettz ( participant . study . timezone_name ) query = ChunkRegistry . objects . filter ( participant = participant ) daily_data_quantities = defaultdict ( lambda : defaultdict ( int ) ) for chunkregistry in query . values_list ( 'time_bin' , 'data_type' , 'file_size' ) : day = chunkregistry [ 0 ] . astimezone ( study_timezone ) . date ( ) filesize = chunkregistry [ 2 ] if filesize is None : filesize = 0 daily_data_quantities [ day ] [ chunkregistry [ 1 ] ] += filesize for day , day_data in daily_data_quantities . items ( ) : data_quantity = { "participant" : participant , "date" : day , "defaults" : { } } for data_type , total_bytes in day_data . items ( ) : if data_type in ALL_DATA_STREAMS : data_quantity [ "defaults" ] [ f"{data_type}_bytes" ] = total_bytes SummaryStatisticDaily . objects . update_or_create ( ** data_quantity )
Update the SummaryStatisticDaily  stats for a participant, using ChunkRegistry data
Update the SummaryStatisticDaily stats for a participant using ChunkRegistry data
""" Update the SummaryStatisticDaily  stats for a participant, using ChunkRegistry data """ # Construct a dict formatted like this: dict[date][data_type] = total_bytes # For each date, create a DataQuantity object
participant
Participant