', IF(next_command_start IS NULL, '-', CONCAT(''))) `CH`, IF(command = 'NODISC', '', IF(next_command_start IS NULL, '-', CONCAT(''))) `ND`, IF(command = 'ZERO', '', IF(next_command_start IS NULL, '-', CONCAT(''))) `ZR`, IF(command = 'NOCHRG', '', IF(next_command_start IS NULL, '-', CONCAT(''))) `NC`, IF(command = 'DISCHARGE', '', IF(next_command_start IS NULL, '-', CONCAT(''))) `DC`, IF(command = 'IDLE', '', IF(next_command_start IS NULL, '-', CONCAT(''))) `ID`, IF(next_command_start > command_start + 3600, CONCAT('[ins]'), '-') AS `ins`, IF(command_start != $start_time AND next_command_start IS NOT NULL AND AVG(epex_price) IS NOT NULL, CONCAT('[del]'), '-') AS `del`, IF(prev_command_start < command_start - 3600 AND command_start != $start_time AND next_command_start IS NOT NULL AND AVG(epex_price) IS NOT NULL, CONCAT('<'), '-') AS `<`, IF((next_command_start > command_start + 3600 OR next_command_start IS NULL) AND command_start != $start_time AND next_command_start IS NOT NULL AND AVG(epex_price) IS NOT NULL, CONCAT('>'), '-') AS `>`, -- btw_percent btw, fee_per_kwh fee, tax_per_kwh tax, epex_price, IFNULL(ROUND((100+btw_percent)*AVG(epex_price+fee_per_kwh+tax_per_kwh), 3), '-') `avg`, IFNULL(ROUND((100+btw_percent)*MAX(epex_price+fee_per_kwh+tax_per_kwh),3), '-') `max`, IFNULL(ROUND((100+btw_percent)*MIN(epex_price+fee_per_kwh+tax_per_kwh),3), '-') `min`, IFNULL(ROUND((100+btw_percent)*AVG(epex_price+fee_per_kwh+tax_per_kwh)/0.84, 3), '-') `sell`, IFNULL(ROUND((100+btw_percent)*AVG(epex_price+fee_per_kwh+tax_per_kwh)*0.84, 3), '-') `buy` FROM ( SELECT commands.command_id, commands.prev_command_id, commands.command, prev_commands.command_start prev_command_start, commands.command_start, next_commands.command_start next_command_start FROM commands LEFT JOIN commands AS prev_commands ON prev_commands.command_id = commands.prev_command_id LEFT JOIN commands AS next_commands ON next_commands.prev_command_id = commands.command_id WHERE commands.command_start >= $start_time ) AS tmp LEFT JOIN epex ON epex_start >= command_start AND epex_start < next_command_start JOIN ( SELECT tax.tax_per_kwh, tax.tax_start, next_tax.tax_start tax_end FROM tax JOIN tax AS next_tax ON next_tax.prev_tax_id = tax.tax_id ) AS ebal ON tax_start <= epex_start AND tax_end > epex_start JOIN ( SELECT fee.fee_per_kwh, fee.fee_start, next_fee.fee_start fee_end FROM fee JOIN fee AS next_fee ON next_fee.prev_fee_id = fee.fee_id ) AS efee ON fee_start <= epex_start AND fee_end > epex_start JOIN ( SELECT btw.btw_percent, btw.btw_start, next_btw.btw_start btw_end FROM btw JOIN btw AS next_btw ON next_btw.prev_btw_id = btw.btw_id ) AS ebtw ON btw_start <= epex_start AND btw_end > epex_start GROUP BY command_id ORDER BY command_start EOQ); html_start(); db_dump_result($res); html_end(); ?>