Skip to content

Commit

Permalink
fix: Fix linting issues and update code
Browse files Browse the repository at this point in the history
  • Loading branch information
9inpachi committed Jun 28, 2021
1 parent 169450c commit dc7d74a
Show file tree
Hide file tree
Showing 25 changed files with 145 additions and 133 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ jobs:
run: |
yarn install
- name: Check Prettier
run: yarn prettier:check
- name: Lint
run: yarn lint

- name: Check Documentation Coverage
run: yarn docs:coverage
Expand Down
10 changes: 5 additions & 5 deletions packages/phoenix-event-display/src/event-display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ export class EventDisplay {
* @returns Promise for loading the geometry.
*/
public loadJSONGeometry(
json: string | object,
json: string | { [key: string]: any },
name: string,
menuNodeName?: string,
scale?: number,
Expand Down Expand Up @@ -462,8 +462,8 @@ export class EventDisplay {
* @param sceneConfiguration Scene configuration containingevent data and detector geometry.
*/
private loadSceneConfiguration(sceneConfiguration: {
eventData: {};
geometries: [];
eventData: { [key: string]: any };
geometries: any[];
}) {
for (const objectType of Object.keys(sceneConfiguration.eventData)) {
const { typeFolder, typeFolderPM } =
Expand Down Expand Up @@ -541,7 +541,7 @@ export class EventDisplay {
this.loadOBJGeometry(filename, name, colour, menuNodeName, doubleSided);
},
loadJSONGeometry: (
json: string | object,
json: string | { [key: string]: any },
name: string,
menuNodeName: string,
scale?: number,
Expand All @@ -557,7 +557,7 @@ export class EventDisplay {
initiallyVisible
);
},
buildGeometryFromParameters: (parameters: object) =>
buildGeometryFromParameters: (parameters: { [key: string]: any }) =>
this.buildGeometryFromParameters(parameters),
scene: this.getThreeManager().getSceneManager().getScene(),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export class CoordinateHelper {
* @returns
*/
public static anglesAreSane(theta: number, phi: number): boolean {
let tmp1 = -Math.PI < phi && Math.PI > phi;
let tmp2 = 0 < theta && Math.PI > theta;
const tmp1 = -Math.PI < phi && Math.PI > phi;
const tmp2 = 0 < theta && Math.PI > theta;
return tmp1 && tmp2;
}

Expand Down Expand Up @@ -49,7 +49,7 @@ export class CoordinateHelper {
phi: number
): Vector3 {
// Threejs uses theta as azimuthal, so need to reverse.
let vector = new Vector3();
const vector = new Vector3();
vector.setFromSphericalCoords(radius, theta, phi);
vector.applyQuaternion(CoordinateHelper.atlasQuaternion());
return vector;
Expand All @@ -67,7 +67,7 @@ export class CoordinateHelper {
eta: number,
phi: number
): Vector3 {
let vector = new Vector3();
const vector = new Vector3();
// Threejs uses theta as azimuthal, so need to reverse.
vector.setFromSphericalCoords(radius, this.etaToTheta(eta), phi);
vector.applyQuaternion(CoordinateHelper.atlasQuaternion());
Expand Down
6 changes: 4 additions & 2 deletions packages/phoenix-event-display/src/helpers/pretty-symbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ export class PrettySymbols {
* @param params Object parameters to be pretty printed.
* @returns New pretty printed parameterss.
*/
public static getPrettyParams(params: { [key: string]: any }): object {
public static getPrettyParams(params: { [key: string]: any }): {
[key: string]: any;
} {
// Create a copy of the params so we don't overwrite the original object
const paramsCopy = Object.assign({}, params);
// Go through all the parameters
Expand All @@ -54,7 +56,7 @@ export class PrettySymbols {

// Pretty print the dparams if any
if (paramsCopy?.dparams) {
const prettyDParams: object = {};
const prettyDParams: { [key: string]: any } = {};

prettyDParams['θ'] = paramsCopy.dparams[3];
prettyDParams['ϕ'] = paramsCopy.dparams[2];
Expand Down
16 changes: 8 additions & 8 deletions packages/phoenix-event-display/src/helpers/rk-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ export class RKHelper {
): any {
const dparams = track.dparams;
// ATLAS uses mm, MeV
let d0 = dparams[0],
z0 = dparams[1],
phi = dparams[2],
theta = dparams[3],
qop = dparams[4];
const d0 = dparams[0];
const z0 = dparams[1];
const phi = dparams[2];
let theta = dparams[3];
const qop = dparams[4];

if (theta < 0) {
theta += Math.PI;
Expand All @@ -65,12 +65,12 @@ export class RKHelper {
}
const q = Math.round(p * qop);

let globalMomentum = CoordinateHelper.sphericalToCartesian(p, theta, phi);
const globalMomentum = CoordinateHelper.sphericalToCartesian(p, theta, phi);

let startPos = CoordinateHelper.sphericalToCartesian(d0, theta, phi);
const startPos = CoordinateHelper.sphericalToCartesian(d0, theta, phi);

// Wipe existing positions
let positions: number[][] = [];
const positions: number[][] = [];
positions.push([startPos.x, startPos.y, startPos.z]);

const startDir = globalMomentum.clone();
Expand Down
10 changes: 5 additions & 5 deletions packages/phoenix-event-display/src/helpers/runge-kutta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ export class RungeKutta {
error_estimate = tryRungeKuttaStep(state.stepSize);
}

let fh: number = state.stepSize;
let fh2: number = Math.pow(fh, 2);
const fh: number = state.stepSize;
const fh2: number = Math.pow(fh, 2);

// Update position and momentum
// state.pos += state.dir * fh + (k1 + k2 + k3) * (fh2 /6)
Expand Down Expand Up @@ -132,19 +132,19 @@ export class RungeKutta {
plength: number = 1000,
inbounds: (pos: Vector3) => boolean = () => true
): { pos: Vector3; dir: Vector3 }[] {
let rkState: State = new State();
const rkState: State = new State();
rkState.pos = startPos;
rkState.dir = startDir;
rkState.p = p;
rkState.q = q;
rkState.maxStepSize = mss;

let result: { pos: Vector3; dir: Vector3 }[] = [];
const result: { pos: Vector3; dir: Vector3 }[] = [];

while (rkState.pathLength < plength) {
rkState.pathLength += RungeKutta.step(rkState);
// Cloning state to avoid using the reference
let copiedState = JSON.parse(JSON.stringify(rkState));
const copiedState = JSON.parse(JSON.stringify(rkState));
result.push({
pos: copiedState.pos,
dir: copiedState.dir,
Expand Down
24 changes: 12 additions & 12 deletions packages/phoenix-event-display/src/loaders/cms-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class CMSLoader extends PhoenixLoader {
) {
this.loadingManager.addLoadableItem('ig_archive');
const igArchive = new JSZip();
let eventsDataInIg = [];
const eventsDataInIg = [];
const readArchive = (res: File | ArrayBuffer) => {
igArchive.loadAsync(res).then(() => {
let allFilesPath = Object.keys(igArchive.files);
Expand Down Expand Up @@ -131,7 +131,7 @@ export class CMSLoader extends PhoenixLoader {
public getEventData(): any {
const eventInfo = this.data?.['Collections']?.['Event_V2']?.[0];

let eventData = {
const eventData = {
runNumber: eventInfo?.[0],
eventNumber: eventInfo?.[1],
ls: eventInfo?.[2],
Expand All @@ -155,7 +155,7 @@ export class CMSLoader extends PhoenixLoader {
eventData.MuonChambers = this.getMuonChambers();

// Undefining object types if there is no event data
for (let objectType of [
for (const objectType of [
'Hits',
'Tracks',
'Jets',
Expand All @@ -176,7 +176,7 @@ export class CMSLoader extends PhoenixLoader {
* @returns An object containing event data for all events.
*/
public getAllEventsData(allEventsDataFromIg: any[]): any {
let allEventsData = {};
const allEventsData = {};
for (const eventData of allEventsDataFromIg) {
this.data = eventData;
allEventsData[eventData.eventPath] = this.getEventData();
Expand All @@ -191,7 +191,7 @@ export class CMSLoader extends PhoenixLoader {
*/
private getTrackingClusters(Hits: any): any {
// These are the collections with point cloud geometries
let clusterCollections = [
const clusterCollections = [
'TrackingRecHits_V1',
'SiStripClusters_V1',
'SiPixelClusters_V1',
Expand Down Expand Up @@ -219,7 +219,7 @@ export class CMSLoader extends PhoenixLoader {
* @returns CaloClusters object containing all CaloClusters collections.
*/
private getCaloClusters(): any {
let caloClustersCollections = ['SuperClusters_V1'];
const caloClustersCollections = ['SuperClusters_V1'];
const CaloClusters = this.getObjectCollections(
caloClustersCollections,
(objectParams) => {
Expand Down Expand Up @@ -277,7 +277,7 @@ export class CMSLoader extends PhoenixLoader {
* @returns MuonChambers object containing all Muon Chambers collections.
*/
private getMuonChambers(): any {
let muonChambersCollections = ['MatchingCSCs_V1', 'MuonChambers_V1'];
const muonChambersCollections = ['MatchingCSCs_V1', 'MuonChambers_V1'];
const MuonChambers = this.getObjectCollections(
muonChambersCollections,
(muonChamberParams) => {
Expand Down Expand Up @@ -308,7 +308,7 @@ export class CMSLoader extends PhoenixLoader {
processObject?: (objectParams: any) => void,
cuts?: { attribute: string; min?: number; max?: number }[]
): any {
let ObjectType = {};
const ObjectType = {};

// Filter to check if the provided collections are indeed inside the data
collections = collections.filter((key) => this.data['Collections'][key]);
Expand All @@ -319,7 +319,7 @@ export class CMSLoader extends PhoenixLoader {
const objectAttributes = this.data['Types'][collection];
// Iterating a single object collection to process all objects
for (const physicsObject of this.data['Collections'][collection]) {
let objectParams = {};
const objectParams = {};
// Filling object params using the given types
objectAttributes.forEach((attribute, attributeIndex) => {
objectParams[attribute[0]] = physicsObject[attributeIndex];
Expand Down Expand Up @@ -366,7 +366,7 @@ export class CMSLoader extends PhoenixLoader {
* @returns Tracks object containing all Tracks collections.
*/
private getTracks(): any {
let Tracks = {};
const Tracks = {};

// All collections with tracks
let tracksCollections = [
Expand Down Expand Up @@ -511,7 +511,7 @@ export class CMSLoader extends PhoenixLoader {
// Create the track curve
curve = new QuadraticBezierCurve3(p1, cp1, p2);

let positions = [];
const positions = [];
// Divide the curve into points to put into positions array
for (const position of curve.getPoints(24)) {
// Increasing the scale to fit Phoenix's event display
Expand All @@ -536,7 +536,7 @@ export class CMSLoader extends PhoenixLoader {
* @returns Metadata of the event.
*/
getEventMetadata(): any[] {
let metadata = super.getEventMetadata();
const metadata = super.getEventMetadata();
const eventInfo = this.data?.['Collections']?.['Event_V2']?.[0];
if (eventInfo?.[3]) {
metadata.push({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ export interface EventDataLoader {
* Get the object containing labels.
* @returns The labels object.
*/
getLabelsObject(): object;
getLabelsObject(): { [key: string]: any };
}
Loading

0 comments on commit dc7d74a

Please sign in to comment.