Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only import files to poto-project once #27 #28

Merged
merged 5 commits into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.4.6",
"version": "0.5.0",
"configurations": [
{
"name": "dev-prepare-dataset1",
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Install [node](https://node.org) latest version and run:
```bash
npm install -g poto-siril
poto -v
# Should print `poto-siril 0.4.6`.
# Should print `poto-siril 0.5.0`.

# Make sure to have `siril` registered in your PATH.
siril -v
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": "poto-siril",
"version": "0.4.6",
"version": "0.5.0",
"description": "Automatization around Siril (<https://siril.org/>) for deep sky astrophotography.",
"bin": {
"poto": "dist/src/poto-siril.js"
Expand Down
4 changes: 3 additions & 1 deletion src/commands/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,16 @@

const autorunFiles = fs.existsSync(autorunDirectory)
? getFitsFromDirectory({
directory: autorunDirectory,

Check warning on line 183 in src/commands/prepare.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 6 spaces but found 8
projectDirectory,

Check warning on line 184 in src/commands/prepare.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 6 spaces but found 8
})

Check warning on line 185 in src/commands/prepare.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 4 spaces but found 6
: [];

const planFiles = fs.existsSync(planDirectory)
? getFitsFromDirectory({
directory: planDirectory,

Check warning on line 190 in src/commands/prepare.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 6 spaces but found 8
projectDirectory,

Check warning on line 191 in src/commands/prepare.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 6 spaces but found 8
})

Check warning on line 192 in src/commands/prepare.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 4 spaces but found 6
: [];

if (autorunFiles.length === 0 && planFiles.length === 0) {
Expand Down Expand Up @@ -449,12 +449,12 @@
for (const lightsFlatsMatch of lightsFlatsMatches) {
const lights = lightsFlatsMatch.isManualMatch
? allLights.filter(
light =>

Check warning on line 452 in src/commands/prepare.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 8 spaces but found 10
light.sequenceId === lightsFlatsMatch.lightSequenceId &&

Check warning on line 453 in src/commands/prepare.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 10 spaces but found 12
light.setName === lightsFlatsMatch.lightSetName,
)

Check warning on line 455 in src/commands/prepare.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 6 spaces but found 8
: allLights.filter(
light => light.setName === lightsFlatsMatch.lightSetName,

Check warning on line 457 in src/commands/prepare.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 8 spaces but found 10
);
if (!lights) {
throw new Error(
Expand Down Expand Up @@ -744,14 +744,16 @@

fs.writeFileSync(potoJsonPath, JSON.stringify(potoProject, null, 2));

let alreadyImported: FileImageSpec[] = [];

for (const layerSet of potoProject.layerSets) {
for (const file of [
...layerSet.lights,
...layerSet.darks,
...layerSet.flats,
...layerSet.biases,
]) {
copyFileToProject(file);
alreadyImported = copyFileToProject(file, alreadyImported);
}
}
};
8 changes: 4 additions & 4 deletions src/commands/preprocess.generate-scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const generateScriptForLightSet = (
fs.mkdirSync(mastersDirectory, { recursive: false });
}

const lightsdirs = [...new Set(set.lights.map(x => x.projectDirectory))];
const lightsdirs = [...new Set(set.lights.map(x => x.projectFileDirectory))];
if (lightsdirs.length === 0) {
throw new Error("No lights found for filter " + set.layerSetId);
}
Expand All @@ -71,7 +71,7 @@ const generateScriptForLightSet = (
}
const lightsDir = path.resolve(lightsdirs[0]);

const flatsDirs = [...new Set(set.flats.map(x => x.projectDirectory))];
const flatsDirs = [...new Set(set.flats.map(x => x.projectFileDirectory))];
if (flatsDirs.length === 0) {
throw new Error("No flats found for filter " + set.layerSetId);
}
Expand All @@ -80,7 +80,7 @@ const generateScriptForLightSet = (
}
const flatsDir = path.resolve(flatsDirs[0]);

const darksDirs = [...new Set(set.darks.map(x => x.projectDirectory))];
const darksDirs = [...new Set(set.darks.map(x => x.projectFileDirectory))];
if (darksDirs.length === 0) {
throw new Error("No darks found for filter " + set.layerSetId);
}
Expand All @@ -89,7 +89,7 @@ const generateScriptForLightSet = (
}
const darksDir = path.resolve(darksDirs[0]);

const biasesDirs = [...new Set(set.biases.map(x => x.projectDirectory))];
const biasesDirs = [...new Set(set.biases.map(x => x.projectFileDirectory))];
if (biasesDirs.length === 0) {
throw new Error("No biases found for filter " + set.layerSetId);
}
Expand Down
480 changes: 274 additions & 206 deletions src/tests/e2e/__snapshots__/e2e-testing.spec.ts.snap

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/utils/const.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const POTO_VERSION = "poto-siril 0.4.6";
export const POTO_VERSION = "poto-siril 0.5.0";

export const POTO_JSON = "_poto_siril.json";

Expand Down
15 changes: 9 additions & 6 deletions src/utils/tests/__snapshots__/utils.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ exports[`utils getFileImageSpecFromFilename should match snapshot (ASIAIR plan t
"fileName": "Light_LDN 1093_120.0s_Bin1_H_gain100_20240707-002348_-10.0C_0001.fit",
"filter": "H",
"gain": 100,
"projectDirectory": "project/bar/H/Light_120.0s_Bin1_H_gain100",
"projectFileDirectory": "project/bar/H/Light_120.0s_Bin1_H_gain100",
"projectFilePath": "project/bar/H/Light_120.0s_Bin1_H_gain100/Light_LDN 1093_120.0s_Bin1_H_gain100_20240707-002348_-10.0C_0001.fit",
"sequenceId": "20240707-002348",
"sequencePosition": 1,
"setName": "Light_120.0s_Bin1_H_gain100",
"sourceDirectory": "input/bar",
"sourceFileDirectory": "input/bar",
"sourceFilePath": "input/bar/Light_LDN 1093_120.0s_Bin1_H_gain100_20240707-002348_-10.0C_0001.fit",
"temperature": -10,
"type": "Light",
Expand All @@ -31,11 +32,12 @@ exports[`utils getFileImageSpecFromFilename should match snapshot (filter named
"fileName": "Light_LDN 1093_120.0s_Bin1_filter h_gain100_20240707-002348_-10.0C_0001.fit",
"filter": "filterh",
"gain": 100,
"projectDirectory": "project/bar/filterh/Light_120.0s_Bin1_filterh_gain100",
"projectFileDirectory": "project/bar/filterh/Light_120.0s_Bin1_filterh_gain100",
"projectFilePath": "project/bar/filterh/Light_120.0s_Bin1_filterh_gain100/Light_LDN 1093_120.0s_Bin1_filter h_gain100_20240707-002348_-10.0C_0001.fit",
"sequenceId": "20240707-002348",
"sequencePosition": 1,
"setName": "Light_120.0s_Bin1_filterh_gain100",
"sourceDirectory": "input/bar",
"sourceFileDirectory": "input/bar",
"sourceFilePath": "input/bar/Light_LDN 1093_120.0s_Bin1_filter h_gain100_20240707-002348_-10.0C_0001.fit",
"temperature": -10,
"type": "Light",
Expand All @@ -52,11 +54,12 @@ exports[`utils getFileImageSpecFromFilename should match snapshot (no filter) 1`
"fileName": "Light_LDN 1093_120.0s_Bin1_gain100_20240707-002348_-10.0C_0001.fit",
"filter": null,
"gain": 100,
"projectDirectory": "project/bar/Light_120.0s_Bin1_gain100",
"projectFileDirectory": "project/bar/Light_120.0s_Bin1_gain100",
"projectFilePath": "project/bar/Light_120.0s_Bin1_gain100/Light_LDN 1093_120.0s_Bin1_gain100_20240707-002348_-10.0C_0001.fit",
"sequenceId": "20240707-002348",
"sequencePosition": 1,
"setName": "Light_120.0s_Bin1_gain100",
"sourceDirectory": "input/bar",
"sourceFileDirectory": "input/bar",
"sourceFilePath": "input/bar/Light_LDN 1093_120.0s_Bin1_gain100_20240707-002348_-10.0C_0001.fit",
"temperature": -10,
"type": "Light",
Expand Down
31 changes: 22 additions & 9 deletions src/utils/tests/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe("utils", () => {
const file = new fs.Dirent();
file.name =
"Light_LDN 1093_120.0s_Bin1_H_gain100_20240707-002348_-10.0C_0001.fit";
file.path = "input/bar";
file.parentPath = "input/bar";
const projectDirectory = "project/bar";
const previousFile = null;

Expand All @@ -29,7 +29,7 @@ describe("utils", () => {
const file = new fs.Dirent();
file.name =
"Light_LDN 1093_120.0s_Bin1_filter h_gain100_20240707-002348_-10.0C_0001.fit";
file.path = "input/bar";
file.parentPath = "input/bar";
const projectDirectory = "project/bar";
const previousFile = null;

Expand All @@ -46,7 +46,7 @@ describe("utils", () => {
const file = new fs.Dirent();
file.name =
"Light_LDN 1093_120.0s_Bin1_gain100_20240707-002348_-10.0C_0001.fit";
file.path = "input/bar";
file.parentPath = "input/bar";
const projectDirectory = "project/bar";
const previousFile = null;

Expand All @@ -66,7 +66,7 @@ describe("utils", () => {
])("should parse bulb in ms (%s)", data => {
const file = new fs.Dirent();
file.name = `Light_LDN 1093_${data.bulb}_Bin1_gain100_20240707-002348_-10.0C_0001.fit`;
file.path = "input/bar";
file.parentPath = "input/bar";
const projectDirectory = "project/bar";
const previousFile = null;

Expand All @@ -84,17 +84,17 @@ describe("utils", () => {
Object.assign(new fs.Dirent(), {
name: "Light_LDN 1093_120.0s_Bin1_H_gain100_20240707-002348_-10.0C_0001.fit",
isFile: () => true,
path: "input/dir",
parentPath: "input/dir",
}),
Object.assign(new fs.Dirent(), {
name: "Light_LDN 1093_120.0s_Bin1_H_gain100_20240707-002349_-10.0C_0002.fit",
isFile: () => true,
path: "input/dir",
parentPath: "input/dir",
}),
Object.assign(new fs.Dirent(), {
name: "Light_LDN 1093_120.0s_Bin1_H_gain100_20240707-002348_-10.0C_0001_thn.jpg",
isFile: () => true,
path: "input/dir",
parentPath: "input/dir",
}),
]);

Expand All @@ -116,16 +116,19 @@ describe("utils", () => {
describe("copyFileToProject", () => {
it("should copy a file to the project directory", () => {
const file = {
projectDirectory: "project/dir",
fileName: "file1.fit",
projectFileDirectory: "project/dir",
projectFilePath: "project/dir/file1.fit",
sourceFilePath: "input/dir/file1.fit",
} as FileImageSpec;

jest.spyOn(fs, "existsSync").mockReturnValue(false);
jest.spyOn(fs, "mkdirSync");
jest.spyOn(fs, "copyFileSync").mockImplementation(() => {});

copyFileToProject(file);
let alreadyImported: FileImageSpec[] = [];

alreadyImported = copyFileToProject(file, alreadyImported);

expect(fs.existsSync).toHaveBeenCalledWith("project/dir");
expect(fs.mkdirSync).toHaveBeenCalledWith("project/dir", {
Expand All @@ -135,6 +138,16 @@ describe("utils", () => {
"input/dir/file1.fit",
"project/dir/file1.fit",
);
expect(alreadyImported).toMatchInlineSnapshot(`
[
{
"fileName": "file1.fit",
"projectFileDirectory": "project/dir",
"projectFilePath": "project/dir/file1.fit",
"sourceFilePath": "input/dir/file1.fit",
},
]
`);
});
});

Expand Down
12 changes: 8 additions & 4 deletions src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,22 @@ export type FileImageSpec = ImageSpec & {
extension: string;

/**
* Path to the ASIAIR dump directory.
* Directory path from the source input directory.
*/
sourceDirectory: string;
sourceFileDirectory: string;
/**
* Path to the file in the ASIAIR dump directory.
* File path file from the source input directory.
*/
sourceFilePath: string;

/**
* Path to the project directory.
*/
projectDirectory: string;
projectFileDirectory: string;
/**
* File path in the project directory.
*/
projectFilePath: string;

/**
* Recorded time.
Expand Down
35 changes: 22 additions & 13 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const getFitsFromDirectory = ({
if (
file.name === ".DS_Store" ||
file.name.startsWith("._") ||
file.path.includes("._")
file.parentPath.includes("._")
) {
return;
}
Expand Down Expand Up @@ -120,25 +120,25 @@ export const getFileImageSpecFromFilename = (
fileName: fileFS.name,
extension: match.groups.extension,

sourceDirectory: fileFS.path,
sourceFilePath: path.join(fileFS.path, fileFS.name),

projectDirectory,
sourceFileDirectory: fileFS.parentPath,
sourceFilePath: path.join(fileFS.parentPath, fileFS.name),
} as FileImageSpec;

file.setName = getSetName(file);

if (["Light", "Flat"].includes(file.type)) {
const directory = file.setName;

file.projectDirectory = file.filter
file.projectFileDirectory = file.filter
? path.join(projectDirectory, file.filter, directory)
: path.join(projectDirectory, directory);
} else {
const directory = `${file.type}_${file.bulb}_${file.bin}_gain${file.gain}`;
file.projectDirectory = path.join(projectDirectory, "any", directory); // We ignore the filter for darks and biases.
file.projectFileDirectory = path.join(projectDirectory, "any", directory); // We ignore the filter for darks and biases.
}

file.projectFilePath = path.join(file.projectFileDirectory, file.fileName);

return file;
} else {
throw new Error(
Expand Down Expand Up @@ -200,15 +200,24 @@ const parseBulbString = (bulbString: string): number => {
}
};

export const copyFileToProject = (file: FileImageSpec) => {
if (!fs.existsSync(file.projectDirectory)) {
fs.mkdirSync(file.projectDirectory, { recursive: true });
export const copyFileToProject = (
file: FileImageSpec,
alreadyImported: FileImageSpec[],
): FileImageSpec[] => {
if (!fs.existsSync(file.projectFileDirectory)) {
fs.mkdirSync(file.projectFileDirectory, { recursive: true });
}

const targetFile = path.join(file.projectDirectory, file.fileName);
fs.copyFileSync(file.sourceFilePath, targetFile);
if (alreadyImported.find(f => f.fileName === file.fileName)) {
logger.debug(`- ${file.fileName} already imported.`);
} else {
fs.copyFileSync(file.sourceFilePath, file.projectFilePath);
alreadyImported.push(file);

logger.debug(`- ${file.fileName} imported.`);
}

logger.debug(`- ${file.fileName} dispatched.`);
return alreadyImported;
};

/**
Expand Down
Loading