Commit c8a9405a authored by Marcel Behrmann's avatar Marcel Behrmann

Page graphql

parent 56794839
[*.ts]
insert_final_newline = true
\ No newline at end of file
......@@ -7,7 +7,8 @@
"eg2.tslint",
"octref.vetur",
"christian-kohler.npm-intellisense",
"gamunu.vscode-yarn"
"gamunu.vscode-yarn",
"editorconfig.editorconfig"
],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": [
......
import * as program from 'commander';
import * as fs from 'fs';
import create from './src/commands/create';
import * as program from "commander";
import * as fs from "fs";
import create from "./src/commands/create";
program
.version('1.0.0')
.option('-t, --token [token]')
.option('-f, --force', 'force creation of day, WARNING: WILL OVERWRITE')
.version("1.0.0")
.option("-t, --token [token]")
.option("-f, --force", "force creation of day, WARNING: WILL OVERWRITE")
.parse(process.argv);
if (!program.args.length) {
......@@ -14,14 +14,14 @@ if (!program.args.length) {
}
if (!program.token) {
if(!fs.existsSync('.token')) {
if (!fs.existsSync(".token")) {
console.error("I can not find an active session, please update session token (-t)");
process.exit(1);
} else {
program.token = fs.readFileSync('.token', 'utf8');
program.token = fs.readFileSync(".token", "utf8");
}
} else {
fs.writeFileSync('.token', program.token);
fs.writeFileSync(".token", program.token);
}
create(program);
import * as program from "commander";
import data from "./src/commands/data";
program
.version("1.0.0")
.option("-a, --all", "Run all days")
.option("-p, --part", "Only generate part of a day")
.option("-l, --logging", "enable day specific logs")
.parse(process.argv);
if (!program.all && program.args.length !== 1) {
process.stderr.write("Day needs to be specified if not all days should be generated.");
}
data(program);
import * as program from 'commander';
import run from './src/commands/run';
import * as program from "commander";
import run from "./src/commands/run";
program
.version('1.0.0')
.option('-p, --partial [part]', 'only run the first part of the day')
.option('-s, --sample', 'run the sample for the day')
.option('-l, --logging', 'enable day specific logs')
.version("1.0.0")
.option("-p, --partial [part]", "only run the first part of the day")
.option("-s, --sample", "run the sample for the day")
.option("-l, --logging", "enable day specific logs")
.parse(process.argv);
if (!program.args.length) {
......
const program = require('commander');
program
.version('2018.3')
.command('run [day]', 'execute the script for a day')
.command('list', 'list the available days')
.parse(process.argv);
\ No newline at end of file
import * as child_process from 'child_process';
import * as fs from 'fs';
import * as path from 'path';
import { leftPad } from './src/Utils';
type part = { num: number, output: string, done: boolean, time: [number, number] };
const calendar: Array<{ day: String, part1: part, part2: part }> = [];
let bin = path.resolve('node_modules', '.bin', 'ts-node');
for (let i = 1; i < 26; i++) {
let day = {
day: leftPad(i.toString(), 2, '0'),
part1: {
num: 1,
output: null,
time: null,
done: true,
},
part2: {
num: 2,
output: null,
time: null,
done: true,
}
};
let res: Buffer = null;
let time: [number, number] = null;
try {
console.log(`Running Day ${i} Part 1`);
time = process.hrtime();
res = child_process.execSync(`${bin} app-run.ts ${i} -p 1`);
day.part1.output = res.toString('utf8');
day.part1.time = process.hrtime(time);
} catch {
day.part1.done = false;
console.log(`Day ${i} Part 1 not available.`);
}
try {
console.log(`Running Day ${i} Part 2`);
time = process.hrtime();
res = child_process.execSync(`${bin} app-run.ts ${i} -p 2`);
day.part2.output = res.toString('utf8');
day.part2.time = process.hrtime(time);
} catch {
day.part2.done = false;
console.log(`Day ${i} Part 2 not available`);
}
calendar.push(day);
}
fs.writeFileSync('./page/data/days.json', JSON.stringify(calendar));
\ No newline at end of file
......@@ -6,7 +6,7 @@
"scripts": {
"day": "ts-node app-run.ts",
"create": "ts-node app-create.ts",
"page:data": "ts-node build-page.ts",
"page:data": "ts-node app-data.ts",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
......
{"day":1,"done":true,"output":"425","part":1,"time":[0,679841346]}
\ No newline at end of file
{"day":1,"done":true,"output":"57538","part":2,"time":[0,760091881]}
\ No newline at end of file
{"day":10,"done":true,"output":"PANLPAPR","part":1,"time":[1,62065539]}
\ No newline at end of file
{"day":10,"done":true,"output":"10304","part":2,"time":[0,963767445]}
\ No newline at end of file
{"day":11,"done":true,"output":"243,49","part":1,"time":[0,812301026]}
\ No newline at end of file
{"day":11,"done":true,"output":"285,169,15","part":2,"time":[1,330784688]}
\ No newline at end of file
{"day":12,"done":true,"output":"2349","part":1,"time":[0,826881515]}
\ No newline at end of file
{"day":12,"done":true,"output":"2100000001168","part":2,"time":[0,872060928]}
\ No newline at end of file
{"day":13,"done":true,"output":"118,112","part":1,"time":[0,956667968]}
\ No newline at end of file
{"day":13,"done":true,"output":"50,21","part":2,"time":[0,997582773]}
\ No newline at end of file
{"day":14,"done":true,"output":"1741551073","part":1,"time":[0,908486714]}
\ No newline at end of file
{"day":14,"done":true,"output":"20322683","part":2,"time":[4,568315785]}
\ No newline at end of file
{"day":15,"done":false,"part":1}
\ No newline at end of file
{"day":15,"done":false,"part":2}
\ No newline at end of file
{"day":16,"done":false,"part":1}
\ No newline at end of file
{"day":16,"done":false,"part":2}
\ No newline at end of file
{"day":17,"done":false,"part":1}
\ No newline at end of file
{"day":17,"done":false,"part":2}
\ No newline at end of file
{"day":18,"done":false,"part":1}
\ No newline at end of file
{"day":18,"done":false,"part":2}
\ No newline at end of file
{"day":19,"done":false,"part":1}
\ No newline at end of file
{"day":19,"done":false,"part":2}
\ No newline at end of file
{"day":2,"done":true,"output":"7410","part":1,"time":[0,797693460]}
\ No newline at end of file
{"day":2,"done":true,"output":"cnjxoritzhvbosyewrmqhgkul","part":2,"time":[0,768502944]}
\ No newline at end of file
{"day":20,"done":false,"part":1}
\ No newline at end of file
{"day":20,"done":false,"part":2}
\ No newline at end of file
{"day":21,"done":false,"part":1}
\ No newline at end of file
{"day":21,"done":false,"part":2}
\ No newline at end of file
{"day":22,"done":false,"part":1}
\ No newline at end of file
{"day":22,"done":false,"part":2}
\ No newline at end of file
{"day":23,"done":false,"part":1}
\ No newline at end of file
{"day":23,"done":false,"part":2}
\ No newline at end of file
{"day":24,"done":false,"part":1}
\ No newline at end of file
{"day":24,"done":false,"part":2}
\ No newline at end of file
{"day":25,"done":false,"part":1}
\ No newline at end of file
{"day":25,"done":false,"part":2}
\ No newline at end of file
{"day":3,"done":true,"output":"118840","part":1,"time":[0,847969891]}
\ No newline at end of file
{"day":3,"done":true,"output":"919","part":2,"time":[0,887641210]}
\ No newline at end of file
{"day":4,"done":true,"output":"102688","part":1,"time":[0,793158493]}
\ No newline at end of file
{"day":4,"done":true,"output":"56901","part":2,"time":[0,837261805]}
\ No newline at end of file
{"day":5,"done":true,"output":"9386","part":1,"time":[1,267300894]}
\ No newline at end of file
{"day":5,"done":true,"output":"4876","part":2,"time":[12,278774927]}
\ No newline at end of file
{"day":6,"done":true,"output":"2917","part":1,"time":[0,917865160]}
\ No newline at end of file
{"day":6,"done":true,"output":"44202","part":2,"time":[0,785453480]}
\ No newline at end of file
{"day":7,"done":true,"output":"GLMVWXZDKOUCEJRHFAPITSBQNY","part":1,"time":[0,810417541]}
\ No newline at end of file
{"day":7,"done":true,"output":"249","part":2,"time":[0,836523755]}
\ No newline at end of file
{"day":8,"done":true,"output":"46096","part":1,"time":[0,781327538]}
\ No newline at end of file
{"day":8,"done":true,"output":"24820","part":2,"time":[0,792408136]}
\ No newline at end of file
{"day":9,"done":true,"output":"394486","part":1,"time":[0,739731709]}
\ No newline at end of file
{"day":9,"done":true,"output":"3276488008","part":2,"time":[2,579235973]}
\ No newline at end of file
[{"day":"01","part1":{"num":1,"output":"425\n","time":[1,242167735],"done":true},"part2":{"num":2,"output":"57538\n","time":[1,148992062],"done":true}},{"day":"02","part1":{"num":1,"output":"7410\n","time":[1,93700103],"done":true},"part2":{"num":2,"output":"cnjxoritzhvbosyewrmqhgkul\n","time":[1,154065058],"done":true}},{"day":"03","part1":{"num":1,"output":"118840\n","time":[1,188785496],"done":true},"part2":{"num":2,"output":"919\n","time":[1,231767105],"done":true}},{"day":"04","part1":{"num":1,"output":"102688\n","time":[1,189689344],"done":true},"part2":{"num":2,"output":"56901\n","time":[1,139910883],"done":true}},{"day":"05","part1":{"num":1,"output":"9386\n","time":[1,781051242],"done":true},"part2":{"num":2,"output":"4876\n","time":[15,477693745],"done":true}},{"day":"06","part1":{"num":1,"output":"2917\n","time":[1,181311726],"done":true},"part2":{"num":2,"output":"44202\n","time":[1,234034899],"done":true}},{"day":"07","part1":{"num":1,"output":"GLMVWXZDKOUCEJRHFAPITSBQNY\n","time":[1,200035440],"done":true},"part2":{"num":2,"output":"249\n","time":[1,277714143],"done":true}},{"day":"08","part1":{"num":1,"output":"46096\n","time":[1,180814799],"done":true},"part2":{"num":2,"output":"24820\n","time":[1,175600807],"done":true}},{"day":"09","part1":{"num":1,"output":"394486\n","time":[1,235113768],"done":true},"part2":{"num":2,"output":"3276488008\n","time":[2,196704530],"done":true}},{"day":"10","part1":{"num":1,"output":"PANLPAPR\n","time":[1,770800704],"done":true},"part2":{"num":2,"output":"10304\n","time":[1,697763540],"done":true}},{"day":"11","part1":{"num":1,"output":"243,49\n","time":[1,232520507],"done":true},"part2":{"num":2,"output":"285,169,15\n","time":[1,778528908],"done":true}},{"day":"12","part1":{"num":1,"output":"2349\n","time":[1,197940003],"done":true},"part2":{"num":2,"output":"2100000001168\n","time":[1,266491737],"done":true}},{"day":"13","part1":{"num":1,"output":"118,112\n","time":[1,309643858],"done":true},"part2":{"num":2,"output":"50,21\n","time":[1,395298997],"done":true}},{"day":"14","part1":{"num":1,"output":"1741551073\n","time":[1,454673824],"done":true},"part2":{"num":2,"output":"20322683\n","time":[3,903443337],"done":true}},{"day":"15","part1":{"num":1,"output":null,"time":null,"done":false},"part2":{"num":2,"output":null,"time":null,"done":false}},{"day":"16","part1":{"num":1,"output":null,"time":null,"done":false},"part2":{"num":2,"output":null,"time":null,"done":false}},{"day":"17","part1":{"num":1,"output":null,"time":null,"done":false},"part2":{"num":2,"output":null,"time":null,"done":false}},{"day":"18","part1":{"num":1,"output":null,"time":null,"done":false},"part2":{"num":2,"output":null,"time":null,"done":false}},{"day":"19","part1":{"num":1,"output":null,"time":null,"done":false},"part2":{"num":2,"output":null,"time":null,"done":false}},{"day":"20","part1":{"num":1,"output":null,"time":null,"done":false},"part2":{"num":2,"output":null,"time":null,"done":false}},{"day":"21","part1":{"num":1,"output":null,"time":null,"done":false},"part2":{"num":2,"output":null,"time":null,"done":false}},{"day":"22","part1":{"num":1,"output":null,"time":null,"done":false},"part2":{"num":2,"output":null,"time":null,"done":false}},{"day":"23","part1":{"num":1,"output":null,"time":null,"done":false},"part2":{"num":2,"output":null,"time":null,"done":false}},{"day":"24","part1":{"num":1,"output":null,"time":null,"done":false},"part2":{"num":2,"output":null,"time":null,"done":false}},{"day":"25","part1":{"num":1,"output":null,"time":null,"done":false},"part2":{"num":2,"output":null,"time":null,"done":false}}]
\ No newline at end of file
......@@ -9,7 +9,12 @@ module.exports = {
siteName: 'EldoranDev',
pathPrefix: '/adventofcode',
titleTemplate: 'EldoranDev - AoC 2018',
plugins: [],
plugins: [
{
use: '~/src/plugins/aoc-data',
options: {},
}
],
chainWebpack: (config, { isServer }) => {
if (isServer) {
config.externals([
......
......@@ -2,11 +2,16 @@
<v-flex xs12 sm6 md6 lg4>
<v-card :color="color" class="white--text pb-2">
<v-card-title>
<div class="headline mb-0">Day {{ day.day }}</div>
<div class="headline mb-0">Day {{ day.number }}</div>
</v-card-title>
<v-expansion-panel dark :value="open" inset>
<part :part="day.part1" v-bind:key="0" v-bind:number="1" :day="day.day" />
<part :part="day.part2" v-bind:key="1" v-bind:number="2" :day="day.day" />
<part
v-for="(part, i) in day.parts"
:part="part"
v-bind:key="i"
v-bind:number="i+1"
:day="day.number"
/>
</v-expansion-panel>
</v-card>
</v-flex>
......@@ -14,7 +19,6 @@
<script>
import Part from "./Part.vue";
import { inflate } from 'zlib';
export default {
data() {
......@@ -38,21 +42,21 @@ export default {
return "red darken-3";
},
open() {
if(!this.part1Solved && !this.part2Solved) {
if (!this.part1Solved && !this.part2Solved) {
return null;
}
if(this.part2Solved && !this.part1Solved) {
if (this.part2Solved && !this.part1Solved) {
return 1;
}
return 0;
},
part1Solved() {
return this.day.part1 !== undefined && this.day.part1.done;
return this.day.parts[0] !== undefined && this.day.parts[0].done;
},
part2Solved() {
return this.day.part2 !== undefined && this.day.part2.done;
return this.day.parts[1] !== undefined && this.day.parts[1].done;
}
},
metaInfo: {
......
......@@ -17,24 +17,29 @@
</v-card-actions>
</v-card>
<v-card v-else>
<v-card-text class="pt-1">Not solved yet.</v-card-text>
<v-card-text class="pt-1">Not solved yet.</v-card-text>
</v-card>
</v-expansion-panel-content>
</template>
<script>
import { leftPad } from '@/utils.js';
export default {
props: {
part: Object,
number: Number,
day: String,
day: Number,
},
computed: {
paddedDay() {
return leftPad(this.day.toString(), 2, '0');
},
inputURL() {
return `data/input/${this.day}-${this.number}.in`;
return `data/input/${this.paddedDay}-${this.number}.in`;
},
sourceURL() {
return `https://gitlab.com/EldoranDev/adventofcode/blob/master/src/days/${this.day}/${this.number}.ts`
return `https://gitlab.com/EldoranDev/adventofcode/blob/master/src/days/${this.paddedDay}/${this.number}.ts`
}
}
}
......
<template>
<Layout>
<day v-for="entry in calendar" v-bind:key="entry.day" :day="entry" />
<day v-for="edge in $page.allDay.edges" v-bind:key="edge.node.id" :day="edge.node" />
</Layout>
</template>
<script>
import data from '../../data/days.json';
import Day from '@/components/Day.vue';
export default {
data() {
return {
calendar: data
calendar: []
};
},
components: {
......@@ -26,3 +24,21 @@ td {
text-align: center;
}
</style>
<page-query>
query {
allDay (sortBy:"number") {
edges {
node{
number,
parts {
part
done
output
time
}
}
}
}
}
</page-query>
\ No newline at end of file
const fs = require('fs');
const path = require('path');
class AoCData {
static defaultOptions() {
return {};
}
constructor(api, options) {
api.loadSource(store => this.loadData(store));
}
loadData(store) {
const day = store.addContentType({
typeName: 'Day',
});
for (let i = 1; i <= 25; i++) {
const p1 = JSON.parse(fs.readFileSync(path.resolve('data', `${i}-1.json`), 'utf8'));
const p2 = JSON.parse(fs.readFileSync(path.resolve('data', `${i}-2.json`), 'utf8'));
day.addNode({
id: i.toString(),
fields: {
number: i,
parts: [
p1,
p2
]
}
});
}
}
}
module.exports = AoCData;
\ No newline at end of file
export const leftPad = (str, length, char) => {
for (let i = str.length; i < length; i++) {
str = `${char}${str}`;
}
return str;
};
\ No newline at end of file
export type Input = Array<string>;
export type Output = Array<string> | string;
\ No newline at end of file
export type Input = string[];
export type Output = string[] | string;
import axios, { AxiosInstance } from 'axios';
import * as fs from 'fs';
import { SSL_OP_NETSCAPE_CHALLENGE_BUG } from 'constants';
import axios, { AxiosInstance } from "axios";
import { SSL_OP_NETSCAPE_CHALLENGE_BUG } from "constants";
import * as fs from "fs";
export default class Client {
private client: AxiosInstance = null;
constructor(token: string) {
this.client = axios.create({
baseURL: 'https://adventofcode.com/2018',
headers: { 'Cookie' : `session=${token}` }
});
baseURL: "https://adventofcode.com/2018",
headers: { Cookie : `session=${token}` },
});
}
public async getInputForDay(num: number): Promise<string> {
let data = '';
let data = "";
try {
data = this.getFromCache(num);
if (data === null) {
const response = await this.client.get(`/day/${num}/input`);
data = response.data;
......@@ -25,25 +25,24 @@ export default class Client {
}
return data;
} catch(error) {
console.log(error);
} catch (error) {
return null;
}
}
private setCache(num: number, data:string) {
if (!fs.existsSync('.cache')) {
fs.mkdirSync('.cache');
private setCache(num: number, data: string) {
if (!fs.existsSync(".cache")) {
fs.mkdirSync(".cache");
}
fs.writeFileSync(`.cache/${num}`, data, {encoding: 'utf8'});
fs.writeFileSync(`.cache/${num}`, data, {encoding: "utf8"});
}
private getFromCache(num: number): string {
if (fs.existsSync('.cache') && fs.existsSync(`.cache/${num}`)) {
return fs.readFileSync(`.cache/${num}`, 'utf8');
if (fs.existsSync(".cache") && fs.existsSync(`.cache/${num}`)) {
return fs.readFileSync(`.cache/${num}`, "utf8");
}
return null;
}
}
\ No newline at end of file
}
import { Output } from "./AoC";
import InputFile from "./io/InputFile";
import InputParser from "./io/InputParser";
import { leftPad } from "./Utils";
import Part from "./Part";
import { leftPad } from "./Utils";
export default class Day {
private part: String;
private day: String;
private part: string;
private day: string;
private parser: InputParser;
constructor(day: String, part: String, parser: InputParser) {
constructor(day: string, part: string, parser: InputParser) {
this.part = part;
this.day = leftPad(day, 2, "0");
this.parser = parser;
}
getDay(): String {
public getDay(): string {
return this.day;
}
async getParts(): Promise<Array<Part>> {
public async getParts(): Promise<Part[]> {
if (this.part) {
return [
new Part(await this.getSolver(this.part), this.part),
......@@ -31,20 +32,24 @@ export default class Day {
}
}
async getInputs(): Promise<Array<InputFile>> {
public async getInputs(): Promise<InputFile[]> {
if (this.part) {
return [
await this.parser.parseFile(this.day, this.part),
];
].filter((i) => i !== null);
} else {
return [
await this.parser.parseFile(this.day, "1"),
await this.parser.parseFile(this.day, "2"),
];
].filter((i) => i !== null);
}
}
async getSolver(part: String): Promise<{ default: Function}> {
return await import(`./days/${this.day}/${part}`);
public async getSolver(part: string): Promise<{ default: () => Output }> {
try {
return await import(`./days/${this.day}/${part}`);
} catch {
return null;
}
}
}
\ No newline at end of file
}
let enabled = false;
class Logger {
write(content: string): void {
if(enabled) {
public write(content: string): void {
if (enabled) {
process.stdout.write(content);
}
}
writeLine(content: string): void {
public writeLine(content: string): void {
if (enabled) {
this.write(`${content}\r\n`);
}
......@@ -20,4 +20,4 @@ export default instance;
export const enableLogger = () => {
enabled = true;
};
\ No newline at end of file