Skip to content

Commit

Permalink
Fixed Csv error and Backend Calls working in MacOs
Browse files Browse the repository at this point in the history
  • Loading branch information
cruizba committed Jun 20, 2018
1 parent c908716 commit c118bc8
Show file tree
Hide file tree
Showing 18 changed files with 83 additions and 68 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {HistoryTimeEntry} from "../../shared/history";
import {HistoryReader} from '../util';
import {HistoryReaderController} from '../util';
import {TimeEntry, Event} from './systemDataTypes/SystemInternalData';

export class HistoryIterator {
private history: HistoryReader;
private history: HistoryReaderController;
private currentFile: Array<HistoryTimeEntry> | undefined;
private pointer: number; // pointer to the time entry is being currently read

public static async create(history: HistoryReader): Promise<HistoryIterator> {
public static async create(history: HistoryReaderController): Promise<HistoryIterator> {
let historyIt: HistoryIterator = new HistoryIterator(history);
try {
historyIt.currentFile = await historyIt.history.nextChangeFile();
Expand All @@ -18,7 +18,7 @@ export class HistoryIterator {
return historyIt;
}

private constructor(history: HistoryReader) {
private constructor(history: HistoryReaderController) {
this.history = history;
this.pointer = -1;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HistoryEntitiesJson } from "../../../shared/history";
import { HistoryReader } from "../../util";
import { HistoryReaderController } from "../../util";
import { User } from "../systemDataTypes/Entities";
import { SystemInfo } from "./absoluteValues/SystemInfo";
import { RentalsAndReturnsPerStation } from "./absoluteValues/rentalsAndReturns/RentalsAndReturnsPerStation";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class RentalsAndReturnsPerStation implements SystemInfo, Observer {
let events: Array<Event> = timeEntry.events;
let key: number | undefined;
let eventStations: Array<Station>;
console.log('Rentals And returns per Station');

for (let event of events) {
eventStations = event.changes.stations;
Expand All @@ -62,6 +63,7 @@ export class RentalsAndReturnsPerStation implements SystemInfo, Observer {
}

case 'EventUserArrivesAtStationToRentBikeWithoutReservation': {
console.log(eventStations);
if (eventStations.length > 0) {
// If only stations with reservations have been recorded, key'll be undefined
key = this.obtainChangedStationId(eventStations);
Expand Down Expand Up @@ -105,8 +107,15 @@ export class RentalsAndReturnsPerStation implements SystemInfo, Observer {
* looking for which station is at that point.
*/
private obtainNotChangedStationId(user: User): number {
let lastPos: number = user.route.old.points.length-1;
let stationPosition: any = user.route.old.points[lastPos];
let stationPosition: any;
if (user.route !== undefined) {
let lastPos: number = user.route.old.points.length-1;
stationPosition = user.route.old.points[lastPos];
}
else {
stationPosition = user.position.new;
}


let stationId = -1;
for(let station of this.basicData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class RentalsAndReturnsPerUser implements SystemInfo, Observer {
public update(timeEntry: TimeEntry): void {
let events: Array<Event> = timeEntry.events;
let key: number;
console.log('Rentals And returns per user');

for(let event of events) {
key = event.changes.users[0].id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class ReservationsPerStation implements SystemInfo, Observer {

public update(reservation: Reservation): void {
let key: number = reservation.station.id;
console.log("Reservations per station");

switch (reservation.type) {
case 'BIKE': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class ReservationsPerUser implements SystemInfo, Observer {

public update(reservation: Reservation): void {
let key: number = reservation.user.id;
console.log("Reservations per user");

switch (reservation.type) {
case 'BIKE': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export class BikesPerStation implements Observer {
let reservationId: number;
let reservation: Reservation | undefined;
let station: Station;

console.log("Bikes per stations");

for(let event of events) {
let eventStations: Array<Station> = event.changes.stations;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HistoryEntitiesJson } from "../../../../shared/history";
import { HistoryReader } from '../../../util/';
import { HistoryReaderController } from '../../../util/';
import { HistoryIterator } from '../../HistoryIterator';
import { Reservation } from '../../systemDataTypes/Entities';
import { Observer, Observable } from '../ObserverPattern';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { HistoryReader } from '../../../util';
import { HistoryReaderController } from '../../../util';
import { HistoryIterator } from '../../HistoryIterator';
import { TimeEntry } from '../../systemDataTypes/SystemInternalData';
import { Observer, Observable } from '../ObserverPattern';
import { Iterator } from './Iterator';

export class TimeEntryIterator implements Iterator {
private observers: Array<Observer>;
private history: HistoryReader;
private history: HistoryReaderController;

public constructor() {
this.observers = new Array<Observer>();
}

public setHistory(history: HistoryReader): void {
public setHistory(history: HistoryReaderController): void {
this.history = history;
}

Expand All @@ -23,6 +23,7 @@ export class TimeEntryIterator implements Iterator {
let timeEntry: TimeEntry | undefined = await it.nextTimeEntry();

while(timeEntry !== undefined) {
console.log(timeEntry);
this.notify(timeEntry);
timeEntry = await it.nextTimeEntry();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { HistoryEntitiesJson } from "../../../../shared/history";
import { HistoryReader } from "../../../util";
import { HistoryReaderController } from "../../../util";
import { Reservation } from "../../systemDataTypes/Entities";

export class SystemReservations {
private reservations: Array<Reservation>;

public async init(history: HistoryReader): Promise<void> {
public async init(history: HistoryReaderController): Promise<void> {
try {
let reservationEntities: HistoryEntitiesJson = await history.getEntities('reservations');
this.reservations = <Reservation[]> reservationEntities.instances;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { HistoryEntitiesJson } from "../../../../shared/history";
import { HistoryReader } from "../../../util";
import { HistoryReaderController } from "../../../util";
import { Station } from "../../systemDataTypes/Entities";

export class SystemStations {
private stations: Array<Station>;

public async init(history: HistoryReader): Promise<void> {
public async init(history: HistoryReaderController): Promise<void> {
try {
let entities: HistoryEntitiesJson = await history.getEntities("stations");
this.stations = <Station[]> entities.instances;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { HistoryEntitiesJson } from "../../../../shared/history";
import { HistoryReader } from "../../../util";
import { HistoryReaderController } from "../../../util";
import { User } from "../../systemDataTypes/Entities";

export class SystemUsers {
private users: Array<User>;

public async init(history: HistoryReader): Promise<void> {
public async init(history: HistoryReaderController): Promise<void> {
try {
let entities: HistoryEntitiesJson = await history.getEntities("users");
this.users = entities.instances;
Expand Down
3 changes: 0 additions & 3 deletions frontend-bikesurbanfleets/src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ export namespace Main {
CsvGeneratorController.enableIpc();

app.on('ready', async () => {
//HistoryReader.enableIpc();
//Settings.enableIpc();
//SchemaFormGenerator.enableIpc();

Main.initWindowsListeners();

Expand Down
43 changes: 23 additions & 20 deletions frontend-bikesurbanfleets/src/main/util/BackendController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,18 @@ export default class BackendController {
reject("Error validating Global Configuration" + globalValidation.errors);
}

const userGen = spawn('java', [
'-jar',
'bikesurbanfleets-config-usersgenerator-1.0.jar',
'-entryPointsInput', '"' + args.entryPointsConfPath + '"',
'-globalInput', '"' + args.globalConfPath + '"',
'-output', '"' + args.outputUsersPath + '/users-configuration.json"',
'-callFromFrontend'
], {
let command = 'java ' +
'-jar ' +
'bikesurbanfleets-config-usersgenerator-1.0.jar ' +
'-entryPointsInput ' + '"' + args.entryPointsConfPath + '" ' +
'-globalInput ' + '"' + args.globalConfPath + '" ' +
'-output ' + '"' + args.outputUsersPath + '/users-configuration.json" ' +
'-callFromFrontend';


const userGen = spawn(command, [], {
cwd: rootPath,
shell: false
shell: true
});

userGen.stderr.on('data', (data) => {
Expand Down Expand Up @@ -161,7 +163,6 @@ export default class BackendController {
globalConf = await fs.readJson(args.globalConfPath);
stationsConf = await fs.readJson(args.stationsConfPath);
usersConf = await fs.readJsonSync(args.usersConfPath);

}
catch {
let errorMessage = "Error reading Configuration Path: \n"
Expand Down Expand Up @@ -201,16 +202,18 @@ export default class BackendController {
reject("Error validating users", + usersValidation.errors);
}

const sim = spawn('java', [
'-DLogFilePath=${HOME}/.Bike3S/',
'-jar',
'bikesurbanfleets-core-1.0.jar',
'-globalConfig', '"' + args.globalConfPath + '"',
'-usersConfig', '"' + args.usersConfPath + '"',
'-stationsConfig', '"' + args.stationsConfPath + '"',
'-historyOutput', '"' + args.outputHistoryPath + '"',
`-callFromFrontend`
], {
// Command should be in an unique string with quotation marks to make it compatible with MacOs
let command = "java " +
"-DLogFilePath=${HOME}/.Bike3S/ " +
"-jar " +
"bikesurbanfleets-core-1.0.jar " +
"-globalConfig " + '"' + args.globalConfPath + '" ' +
"-usersConfig " + '"' + args.usersConfPath + '" ' +
"-stationsConfig " + '"' + args.stationsConfPath + '" ' +
"-historyOutput " + '"' + args.outputHistoryPath + '" '+
"-callFromFrontend";

const sim = spawn(command, [], {
cwd: rootPath,
shell: true
});
Expand Down
14 changes: 7 additions & 7 deletions frontend-bikesurbanfleets/src/shared/BackendInterfaces.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export interface UserGeneratorArgs {
globalConfPath: string,
entryPointsConfPath: string,
outputUsersPath: string
globalConfPath: string;
entryPointsConfPath: string;
outputUsersPath: string;
}

export interface CoreSimulatorArgs {
globalConfPath: string,
stationsConfPath: string,
usersConfPath: string,
outputHistoryPath: string
globalConfPath: string;
stationsConfPath: string;
usersConfPath: string;
outputHistoryPath: string;
}
36 changes: 18 additions & 18 deletions fuse.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,28 +77,28 @@ maven.on('error', (error) => {

maven.on('close', (code) => {
if (code === 0) {
let dirs = fs.readdirSync(projectRoot.backendRoot());
dirs = dirs.filter(dirName => dirName.startsWith("backend-bikesurbanfleets"))
.map(dirName => path.join(projectRoot.backendRoot(), `${dirName}/target`));
let dirs = fs.readdirSync(projectRoot.backendRoot());
dirs = dirs.filter(dirName => dirName.startsWith("backend-bikesurbanfleets"))
.map(dirName => path.join(projectRoot.backendRoot(), `${dirName}/target`));

dirs.forEach(dirName => {
fs.readdirSync(dirName).filter((file) => file.endsWith('jar-with-dependencies.jar')).forEach((file) => {
const target = path.join(dirName, file);
const destination = path.join(projectRoot.build(), file.replace('-jar-with-dependencies', ''));
dirs.forEach(dirName => {
fs.readdirSync(dirName).filter((file) => file.endsWith('jar-with-dependencies.jar')).forEach((file) => {
const target = path.join(dirName, file);
const destination = path.join(projectRoot.build(), file.replace('-jar-with-dependencies', ''));

fs.copySync(target, destination);
fs.copySync(target, destination);

log.time().green(`finished packaging ${file}`).echo();
})
});
log.time().green(`finished packaging ${file}`).echo();
})
});

log.time().green('backend-bikesurbanfleets build finished').echo();
resolve();
} else {
log.time().red(`maven finished with error code ${code}`).echo();
reject();
}
});
log.time().green('backend-bikesurbanfleets build finished').echo();
resolve();
} else {
log.time().red(`maven finished with error code ${code}`).echo();
reject();
}
});
}));

Sparky.task('build:schema', ['clean:cache:schema'], () => new Promise((resolve, reject) => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Bike3S",
"version": "0.5.0",
"version": "0.6.0",
"main": "frontend/main.js",
"author": "URJC <[email protected]>",
"homepage": "https://github.com/stimonm/Bike3S",
Expand Down
4 changes: 2 additions & 2 deletions package_production.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Bike3S",
"version": "0.5.0",
"version": "0.6.0",
"main": "frontend/main.js",
"author": "URJC <[email protected]>",
"homepage": "https://github.com/stimonm/Bike3S",
Expand All @@ -26,7 +26,7 @@
]
},
"dependencies": {
"ajv": "^6.0.0",
"ajv": "^5.0.0",
"angular-in-memory-web-api": "^0.5.2",
"angular2-toaster": "^5.0.1",
"csvtojson": "^1.1.9",
Expand Down

0 comments on commit c118bc8

Please sign in to comment.