task.query('''
    INSERT INTO
        `inventory`(`station`, `mode`, `start`)
    SELECT
        `station`,
        'H' AS `mode`,
        MIN(`mindate`) AS `start` FROM (
            (SELECT
                `station`,
                DATE(MIN(`time`)) as `mindate`
            FROM `hourly_synop`
            GROUP BY `station`)
        UNION ALL
            (SELECT
                `station`,
                DATE(MIN(`time`)) as `mindate`
            FROM `hourly_metar`
            GROUP BY `station`)
        UNION ALL
            (SELECT
                `station`,
                DATE(MIN(`time`)) as `mindate`
            FROM `hourly_national`
            GROUP BY `station`)
        UNION ALL
            (SELECT
                `station`,
                DATE(MIN(`time`)) as `mindate`
            FROM `hourly_isd`
            GROUP BY `station`)
        ) AS `hourly_inventory`
    GROUP BY `station`
    ON DUPLICATE KEY UPDATE
        `start` = VALUES(`start`)
''')
Example #2
0
from routines import Routine

task = Routine('task.inventory.daily')

task.query('''
    INSERT INTO
        `inventory`(`station`, `mode`, `start`)
    SELECT
        `station`,
        'D' AS `mode`,
        MIN(`mindate`) AS `start` FROM (
            (SELECT
                `station`,
                MIN(`date`) as `mindate`
            FROM `daily_national`
            GROUP BY `station`)
        UNION ALL
            (SELECT
                `station`,
                MIN(`date`) as `mindate`
            FROM `daily_ghcn`
            GROUP BY `station`)
        ) AS `daily_inventory`
    GROUP BY `station`
    ON DUPLICATE KEY UPDATE
        `start` = VALUES(`start`)
''')

task.query('''
    INSERT INTO
        `inventory`(`station`, `mode`, `end`)