From afdb091f5b0247ae6ee88e3194893ae42a82655f Mon Sep 17 00:00:00 2001 From: brauliorivas Date: Thu, 6 Jun 2024 00:55:48 +0000 Subject: [PATCH] =?UTF-8?q?Deploy=20preview=20for=20PR=2025=20=F0=9F=9B=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...964a1e325ed338ecd63a990839efa6ecdd023.idx} | Bin 12216 -> 12216 bytes ...64a1e325ed338ecd63a990839efa6ecdd023.pack} | Bin 151611 -> 151611 bytes ...964a1e325ed338ecd63a990839efa6ecdd023.rev} | Bin 1644 -> 1644 bytes pr-preview/pr-25/js/types/dynamic.js | 15 ++ pr-preview/pr-25/js/types/load.js | 32 +-- pr-preview/pr-25/js/types/reconstruction.js | 30 ++- pr-preview/pr-25/js/types/version.js | 8 +- pr-preview/pr-25/test/load.test.js | 235 ++++++++++++------ pr-preview/pr-25/test/reconstruction.test.js | 49 ++++ pr-preview/pr-25/test/version.test.js | 78 ++++++ 10 files changed, 325 insertions(+), 122 deletions(-) rename pr-preview/pr-25/bare_pr_preview/objects/pack/{pack-378923358f7fe31a0e073b92765141e67fcb5579.idx => pack-cee964a1e325ed338ecd63a990839efa6ecdd023.idx} (97%) rename pr-preview/pr-25/bare_pr_preview/objects/pack/{pack-378923358f7fe31a0e073b92765141e67fcb5579.pack => pack-cee964a1e325ed338ecd63a990839efa6ecdd023.pack} (99%) rename pr-preview/pr-25/bare_pr_preview/objects/pack/{pack-378923358f7fe31a0e073b92765141e67fcb5579.rev => pack-cee964a1e325ed338ecd63a990839efa6ecdd023.rev} (91%) create mode 100644 pr-preview/pr-25/js/types/dynamic.js create mode 100644 pr-preview/pr-25/test/reconstruction.test.js create mode 100644 pr-preview/pr-25/test/version.test.js diff --git a/pr-preview/pr-25/bare_pr_preview/objects/pack/pack-378923358f7fe31a0e073b92765141e67fcb5579.idx b/pr-preview/pr-25/bare_pr_preview/objects/pack/pack-cee964a1e325ed338ecd63a990839efa6ecdd023.idx similarity index 97% rename from pr-preview/pr-25/bare_pr_preview/objects/pack/pack-378923358f7fe31a0e073b92765141e67fcb5579.idx rename to pr-preview/pr-25/bare_pr_preview/objects/pack/pack-cee964a1e325ed338ecd63a990839efa6ecdd023.idx index 064be2d538a3d6fb96008f0218b024c2c05a8dca..f0ad81a09bae5bb331893805910082d34eaa8720 100644 GIT binary patch delta 78 zcmV-U0I~nLU$|eeCMyDEyOSs@G6G@=lUyt60$$FuNGzHG0%bk3!py8;-l=TbU;kK&kKKAwS)k*y`qQD6^E%jU Wrp%taeA (links[type] = [])); return links; @@ -225,7 +225,12 @@ export function createGenericLink(id, from, { collectionID, index }) { return genericLink; } -function extractOneToManyLinks(linksManager, keys, newParticle, particleData) { +export function extractOneToManyLinks( + linksManager, + keys, + newParticle, + particleData +) { for (const key of keys) { particleData[key].map((val) => { const link = createGenericLink( @@ -239,7 +244,12 @@ function extractOneToManyLinks(linksManager, keys, newParticle, particleData) { } } -function extractOneToOneLink(linksManager, key, newParticle, particleData) { +export function extractOneToOneLink( + linksManager, + key, + newParticle, + particleData +) { const link = createGenericLink( linksManager[key].length, newParticle.index, @@ -248,3 +258,11 @@ function extractOneToOneLink(linksManager, key, newParticle, particleData) { linksManager[key].push(link); newParticle[key] = link.id; } + +export const types = { + "Cluster": Cluster, + "ParticleID": ParticleID, + "ReconstructedParticle": ReconstructedParticle, + "Vertex": Vertex, + "Track": Track, +}; diff --git a/pr-preview/pr-25/js/types/version.js b/pr-preview/pr-25/js/types/version.js index dd710ca4..2d1efad8 100644 --- a/pr-preview/pr-25/js/types/version.js +++ b/pr-preview/pr-25/js/types/version.js @@ -12,18 +12,18 @@ export class Version { greaterOrEqualThan(version) { return ( - this.major >= version.major || + this.major > version.major || (this.major === version.major && - (this.minor >= version.minor || + (this.minor > version.minor || (this.minor === version.minor && this.patch >= version.patch))) ); } lessOrEqualThan(version) { return ( - this.major <= version.major || + this.major < version.major || (this.major === version.major && - (this.minor <= version.minor || + (this.minor < version.minor || (this.minor === version.minor && this.patch <= version.patch))) ); } diff --git a/pr-preview/pr-25/test/load.test.js b/pr-preview/pr-25/test/load.test.js index 1f35effe..38f42d24 100644 --- a/pr-preview/pr-25/test/load.test.js +++ b/pr-preview/pr-25/test/load.test.js @@ -1,85 +1,6 @@ import { buildLoader, loadParticles } from "../js/types/load"; - -const data = { - "Event 0": { - "EFlowPhoton": { - "collID": 7, - "collType": "edm4hep::ClusterCollection", - "collection": [ - { - "clusters": [], - "directionError": { - "x": 0.0, - "y": 0.0, - "z": 0.0, - }, - "energy": 6.2020978927612305, - "energyError": 0.0, - "hits": [], - "iTheta": 0.0, - "particleIDs": [], - "phi": 0.0, - "position": { - "x": 0.0, - "y": 0.0, - "z": 0.0, - }, - "positionError": [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - "shapeParameters": [], - "subdetectorEnergies": [], - "type": 0, - }, - ], - }, - "ReconstructedParticles": { - "collID": 14, - "collType": "edm4hep::ReconstructedParticleCollection", - "collection": [ - { - "charge": 1.0, - "clusters": [], - "covMatrix": [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], - "energy": 0.358455091714859, - "goodnessOfPID": 0.0, - "mass": 0.13957038521766663, - "momentum": { - "x": 0.09558331221342087, - "y": -0.11288221180438995, - "z": -0.2951807975769043, - }, - "particleIDUsed": { - "collectionID": -2, - "index": -2, - }, - "particleIDs": [ - { - "collectionID": 4, - "index": 0, - }, - ], - "particles": [], - "referencePoint": { - "x": 0.0, - "y": 0.0, - "z": 0.0, - }, - "startVertex": { - "collectionID": -2, - "index": -2, - }, - "tracks": [ - { - "collectionID": 3, - "index": 0, - }, - ], - "type": 0, - }, - ], - }, - "edm4hepVersion": "0.7.0", - }, -}; +import { dynamicLoad } from "../js/types/dynamic.js"; +import { ReconstructedParticle } from "../js/types/reconstruction"; describe("build loader", () => { it("should create a loader with a set of types", () => { @@ -93,6 +14,91 @@ describe("build loader", () => { }); describe("load different types of particles", () => { + let data = {}; + + beforeAll(() => { + data = { + "Event 0": { + "EFlowPhoton": { + "collID": 7, + "collType": "edm4hep::ClusterCollection", + "collection": [ + { + "clusters": [], + "directionError": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + }, + "energy": 6.2020978927612305, + "energyError": 0.0, + "hits": [], + "iTheta": 0.0, + "particleIDs": [], + "phi": 0.0, + "position": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + }, + "positionError": [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], + "shapeParameters": [], + "subdetectorEnergies": [], + "type": 0, + }, + ], + }, + "ReconstructedParticles": { + "collID": 14, + "collType": "edm4hep::ReconstructedParticleCollection", + "collection": [ + { + "charge": 1.0, + "clusters": [], + "covMatrix": [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], + "energy": 0.358455091714859, + "goodnessOfPID": 0.0, + "mass": 0.13957038521766663, + "momentum": { + "x": 0.09558331221342087, + "y": -0.11288221180438995, + "z": -0.2951807975769043, + }, + "particleIDUsed": { + "collectionID": -2, + "index": -2, + }, + "particleIDs": [ + { + "collectionID": 4, + "index": 0, + }, + ], + "particles": [], + "referencePoint": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + }, + "startVertex": { + "collectionID": -2, + "index": -2, + }, + "tracks": [ + { + "collectionID": 3, + "index": 0, + }, + ], + "type": 0, + }, + ], + }, + "edm4hepVersion": "0.7.0", + }, + }; + }); + it("should only load particles of one type", () => { const loadersConfig = "ReconstructedParticle"; @@ -111,3 +117,70 @@ describe("load different types of particles", () => { ); }); }); + +describe("dynamically load an object", () => { + let particleData = {}; + let reconstructedParticle; + + beforeAll(() => { + particleData = { + "PDG": 3, + "charge": 0.0, + "clusters": [], + "covMatrix": { + "values": [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], + }, + "energy": 9.644623756408691, + "goodnessOfPID": 0.0, + "mass": 0.45484575629234314, + "momentum": { + "x": -4.557793617248535, + "y": -6.684719085693359, + "z": 5.230002403259277, + }, + "particles": [ + { + "collectionID": 4196981182, + "index": 20, + }, + { + "collectionID": 4196981182, + "index": 19, + }, + ], + "referencePoint": { + "x": -1.2017582654953003, + "y": -2.118278741836548, + "z": 1.424477458000183, + }, + "startVertex": { + "collectionID": 4294967295, + "index": -1, + }, + "tracks": [], + }; + }); + + beforeEach(() => { + reconstructedParticle = new ReconstructedParticle(); + reconstructedParticle.index = 0; + }); + + it("should load all the properties of an object", () => { + dynamicLoad(reconstructedParticle, particleData); + + expect(reconstructedParticle).toMatchObject(particleData); + }); + + it("should ignore some properties of an object", () => { + const ignore = new Set(["PDG", "charge", "particles"]); + + dynamicLoad(reconstructedParticle, particleData, ignore); + expect(reconstructedParticle).toMatchObject({ + ...particleData, + PDG: 0, + charge: 0, + particles: [], + }); + }); +}); diff --git a/pr-preview/pr-25/test/reconstruction.test.js b/pr-preview/pr-25/test/reconstruction.test.js new file mode 100644 index 00000000..90278d6f --- /dev/null +++ b/pr-preview/pr-25/test/reconstruction.test.js @@ -0,0 +1,49 @@ +import { + extractOneToManyLinks, + extractOneToOneLink, + createLinksManager, + createGenericLink, + GenericLink, +} from "../js/types/reconstruction.js"; + +test("it should create a generic link", () => { + const link = createGenericLink(1, 2, { collectionID: 3, index: 4 }); + expect(link.id).toBe(1); + expect(link.from).toBe(2); + expect(link.to).toBe(4); + expect(link.collectionID).toBe(3); +}); + +test("it should create a links manager", () => { + const linksManager = createLinksManager(["a", "b"]); + expect(linksManager).toEqual({ a: [], b: [] }); +}); + +test("it should extract one-to-many links", () => { + const linksManager = { a: [], b: [] }; + const keys = ["a", "b"]; + const newParticle = { index: 0, a: [], b: [] }; + const particleData = { + a: [{ collectionID: 1, index: 2 }], + b: [{ collectionID: 3, index: 4 }], + }; + const firstLink = createGenericLink(0, 0, { collectionID: 1, index: 2 }); + const secondLink = createGenericLink(0, 0, { collectionID: 3, index: 4 }); + + extractOneToManyLinks(linksManager, keys, newParticle, particleData); + expect(linksManager).toEqual({ a: [firstLink], b: [secondLink] }); + expect(newParticle.a).toEqual([0]); + expect(newParticle.b).toEqual([0]); +}); + +test("it should extract one-to-one link", () => { + const linksManager = { a: [] }; + const key = "a"; + const newParticle = { index: 0, a: [] }; + const particleData = { a: { collectionID: 1, index: 2 } }; + const link = createGenericLink(0, 0, { collectionID: 1, index: 2 }); + + extractOneToOneLink(linksManager, key, newParticle, particleData); + expect(linksManager).toEqual({ a: [link] }); + expect(newParticle.a).toEqual(0); +}); diff --git a/pr-preview/pr-25/test/version.test.js b/pr-preview/pr-25/test/version.test.js new file mode 100644 index 00000000..dd4063bb --- /dev/null +++ b/pr-preview/pr-25/test/version.test.js @@ -0,0 +1,78 @@ +import { Version, compatible } from "../js/types/version.js"; + +describe("version class methods", () => { + let version; + + beforeAll(() => { + version = new Version("1.12.4"); + }); + + it("should return a string", () => { + expect(version.toString()).toBe("1.12.4"); + }); + + describe("greater version than current", () => { + let greaterVersion; + + beforeAll(() => { + greaterVersion = new Version("1.12.5"); + }); + + it("should return false", () => { + expect(version.greaterOrEqualThan(greaterVersion)).toBe(false); + }); + + it("should return true", () => { + expect(version.lessOrEqualThan(version)).toBe(true); + }); + }); + + describe("smaller version than current", () => { + let lessVersion; + + beforeAll(() => { + lessVersion = new Version("1.5.4"); + }); + + it("should return false", () => { + expect(version.lessOrEqualThan(lessVersion)).toBe(false); + }); + + it("should return true", () => { + expect(version.greaterOrEqualThan(version)).toBe(true); + }); + }); + + it("should return true if version is between", () => { + const version1 = new Version("1.0.0"); + const version2 = new Version("2.0.0"); + + expect(version.isBetween(version1, version2)).toBe(true); + }); + + it("should return false if version is not between", () => { + const version1 = new Version("0.7.0"); + const version2 = new Version("1.12.3"); + + expect(version.isBetween(version1, version2)).toBe(false); + }); +}); + +describe("compatible function", () => { + let type; + + beforeAll(() => { + type = { + MIN_VERSION: "0.7.0", + MAX_VERSION: "1.0.0", + }; + }); + + it("should be compatible", () => { + expect(compatible(type, "0.7.0")).toBe(true); + }); + + it("should not be compatible with a greater version", () => { + expect(compatible(type, "1.0.1")).toBe(false); + }); +});