amaran-light-cli
Version:
Command line tool for controlling Aputure Amaran lights via WebSocket to a local Amaran desktop app.
70 lines • 3.23 kB
JavaScript
import * as fs from 'node:fs';
import * as path from 'node:path';
import chalk from 'chalk';
import { CURVE_HELP_TEXT } from '../../daylightSimulation/constants.js';
import { graphSchedule } from '../../daylightSimulation/graphSchedule.js';
import { ScheduleMaker } from '../../daylightSimulation/scheduleMaker.js';
export function registerGraphSchedule(program, deps) {
const { asyncCommand } = deps;
program
.command('graph')
.description('Generate a graph of the auto-cct schedule')
.option('-y, --lat <latitude>', 'Manual latitude (-90 to 90)')
.option('-x, --lon <longitude>', 'Manual longitude (-180 to 180)')
.option('-d, --date <date>', 'Date to preview (ISO format, e.g., 2025-10-26)')
.option('-C, --curve <curve>', CURVE_HELP_TEXT)
.option('-o, --output <filename>', 'Output filename (default: schedule-<date>.png)')
.option('-W, --width <width>', 'Image width in pixels (default: 1200)', '1200')
.option('-H, --height <height>', 'Image height in pixels (default: 600)', '600')
.option('-m, --metrics <type>', 'Metrics to graph: cct, intensity, lux, both, or all (default: both)', 'both')
.option('--cloud-cover <value>', 'Cloud cover (0-1)')
.option('--precipitation <type>', 'Precipitation type')
.action(asyncCommand(handleGraphSchedule(deps)));
}
function handleGraphSchedule(deps) {
return async (options) => {
const maker = new ScheduleMaker(deps);
let schedule;
try {
// For graphing, we want minute-by-minute granularity for a smooth curve
schedule = await maker.makeSchedule({
lat: options.lat,
lon: options.lon,
date: options.date,
intervalMinutes: 1,
curves: options.curve,
includeSpecialTimes: false, // Cleaner graph with regular intervals
bufferMinutes: 30,
cloudCover: options.cloudCover,
precipitation: options.precipitation,
});
}
catch (error) {
console.error(chalk.red(error.message));
process.exit(1);
}
try {
const buffer = await graphSchedule(schedule, {
width: options.width ? parseInt(options.width, 10) : undefined,
height: options.height ? parseInt(options.height, 10) : undefined,
metrics: options.metrics,
});
let filename = options.output;
if (!filename) {
const dateStr = schedule.date.toISOString().split('T')[0];
filename = `schedule-${dateStr}.png`;
}
if (!filename.toLowerCase().endsWith('.png'))
filename += '.png';
const outputPath = path.resolve(process.cwd(), filename);
fs.writeFileSync(outputPath, buffer);
console.log(chalk.green(`Graph saved to ${outputPath}`));
}
catch (error) {
console.error(chalk.red('Error generating graph:'), error);
process.exit(1);
}
};
}
export default registerGraphSchedule;
//# sourceMappingURL=graphSchedule.js.map