added switch for counter or timestap sort, new imagefinder

This commit is contained in:
Hendrik Schutter 2019-02-21 22:34:35 +01:00
parent 6b4c3dbc5d
commit 0627b40f9b
6 changed files with 239 additions and 72 deletions

28
Server_TLC_PostSW.txt Normal file
View File

@ -0,0 +1,28 @@
java -jar TLC_PostSW.jar -log -m createDB -r /home/hendrik/ftp/files/camera01/ -p /home/hendrik/TLC_PostSW/TLC01/ -n 83584
java -jar TLC_PostSW.jar -log -m createDB -r /home/hendrik/ftp/files/camera02/ -p /home/hendrik/TLC_PostSW/TLC02/ -n 83538
java -jar TLC_PostSW.jar -log -m createDB -r /home/hendrik/ftp/files/camera04/ -p /home/hendrik/TLC_PostSW/TLC04/ -n 11935
printf "TLC01: " && tail -n 1 ./TLC01/log01.txt && printf "TLC01: " && tail -n 1 ./TLC02/log02.txt && printf "TLC01: " && tail -n 1 ./TLC04/log04.txt
while true; do
clear
printf "TLC01: " && tail -n 1 ./TLC01/log01.txt && printf "TLC01: " && tail -n 1 ./TLC02/log02.txt && printf "TLC01: " && tail -n 1 ./TLC04/log04.txt
printf "\n"
sleep 1
done
-log -m createDB -r /home/hendrik/Schreibtisch/Geiger_Timelaspe/Rohdaten/ -p /home/hendrik/Schreibtisch/Post_Sort/-i time -n 10
19711

View File

@ -60,6 +60,9 @@ class DBController
}
}
});
System.out.println("Connect geklappt");
}
public void createTableImages()
@ -73,6 +76,7 @@ class DBController
} catch (SQLException e) {
System.err.println("Couldn't handle DB-Query");
e.printStackTrace();
System.exit(-1);
}
}

View File

@ -1,36 +1,35 @@
import java.io.File;
import java.io.FileFilter;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import org.apache.commons.io.filefilter.WildcardFileFilter;
public class ImageFinder
public abstract class ImageFinder
{
short maxYears = 5;
int lengthRootFolder;
String rootFolder;
int currentYear = 0;
int currentMonth = 0;
static short maxYears = 5;
String[] monthNames = { "01_January", "02_February", "03_March",
"04_April", "05_May", "06_June", "07_July", "08_August",
"09_September", "10_October", "11_November", "12_December" };
int lengthRootFolder;
Boolean[][] month = new Boolean[maxYears][12];
static String rootFolder;
static int currentYear = 0;
static int currentMonth = 0;
static String[] monthNames = { "01_January", "02_February", "03_March", "04_April",
"05_May", "06_June", "07_July", "08_August", "09_September",
"10_October", "11_November", "12_December" };
static Boolean[][] month = new Boolean[maxYears][12];
static String[] years = new String[maxYears];
String[] years = new String[maxYears];
public ImageFinder(String rootFolder)
{
this.rootFolder = rootFolder;
lengthRootFolder = rootFolder.length();
}
String findStartyear()
String findStartyear()
{
boolean next = true;
int i = 0; // start year
@ -96,44 +95,8 @@ public class ImageFinder
}
}
public String getImagePath(int imageCounter)
{
String path = null;
for (int i = currentYear; i < years.length; i++) {
if (years[i] != null) {
for (int j = currentMonth; j < month[i].length; j++) {
if(month[i][j]) {
//System.out.println("Patth: " + rootFolder + years[i] + "/" + monthNames[j] + "/" );
File dir = new File(rootFolder + years[i] + "/" + monthNames[j] + "/");
FileFilter fileFilter = new WildcardFileFilter(
"*" + convertImageCounter(imageCounter) + "*.jpg");
File[] files = dir.listFiles(fileFilter);
path = Arrays.toString(files);
path = path.replace("[", "");
path = path.replace("]", "");
if ((path == "null") || (files.length == 0)) {
//Nicht gefunden
//System.out.println("error404");
}else {
//Gefunden
currentMonth = j;
currentYear = i;
return path.substring(lengthRootFolder);
}
}
}
currentMonth = 0;
}
}
return "404";
}
private String convertImageCounter(int imageCounter)
protected String convertImageCounter(int imageCounter)
{
switch ((int) (Math.log10(imageCounter) + 1)) {
case 1:
@ -153,4 +116,6 @@ public class ImageFinder
}
}
public abstract String getImagePath(int imageCounter);
}

View File

@ -0,0 +1,51 @@
import java.io.File;
import java.io.FileFilter;
import java.util.Arrays;
import org.apache.commons.io.filefilter.WildcardFileFilter;
public class ImageFinderCounter extends ImageFinder
{
public ImageFinderCounter(String rootFolder)
{
super(rootFolder);
// TODO Auto-generated constructor stub
}
public String getImagePath(int imageCounter)
{
String path = null;
for (int i = currentYear; i < years.length; i++) {
if (years[i] != null) {
for (int j = currentMonth; j < month[i].length; j++) {
if (month[i][j]) {
// System.out.println("Patth: " + rootFolder + years[i] + "/"
// + monthNames[j] + "/" );
File dir = new File(
rootFolder + years[i] + "/" + monthNames[j] + "/");
FileFilter fileFilter = new WildcardFileFilter(
"*" + convertImageCounter(imageCounter) + "*.jpg");
File[] files = dir.listFiles(fileFilter);
path = Arrays.toString(files);
path = path.replace("[", "");
path = path.replace("]", "");
if ((path == "null") || (files.length == 0)) {
// Nicht gefunden
// System.out.println("error404");
} else {
// Gefunden
currentMonth = j;
currentYear = i;
return path.substring(lengthRootFolder);
}
}
}
currentMonth = 0;
}
}
return "404";
}
}

View File

@ -0,0 +1,97 @@
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Arrays;
import java.util.Comparator;
import org.apache.commons.io.filefilter.WildcardFileFilter;
public class ImageFinderTimestamp extends ImageFinder
{
public ImageFinderTimestamp(String rootFolder)
{
super(rootFolder);
// TODO Auto-generated constructor stub
}
static int sortedimagecounter = 0;
static int fileslenght = 0;
static File[] files = null;
private static void sortImages()
{
// System.out.println("Path: " + rootFolder + years[i] + "/"
// + monthNames[j] + "/" );
/*
* File dir = new File( rootFolder + years[i] + "/" + monthNames[j] +
* "/");
*/
File dir = new File(rootFolder + "/");
files = dir.listFiles();
fileslenght = files.length;
System.out.println("File lenght: " + fileslenght);
System.exit(0);
sortFilesByDateCreated(files);
sortedimagecounter = 0;
/*
* for (int k = 0; k < files.length; k++) {
* System.out.println(files[k].getName()); }
*/
}
public String getImagePath(int imageCounter)
{
String path = null;
if (sortedimagecounter != (fileslenght - 1)) {
System.out.println("sort new Images");
sortImages();
path = files[sortedimagecounter].getAbsolutePath();
sortedimagecounter++;
return path;
} else {
path = files[sortedimagecounter].getAbsolutePath();
sortedimagecounter++;
return path;
}
}
public static void sortFilesByDateCreated(File[] files)
{
Arrays.sort(files, new Comparator<File>() {
public int compare(File f1, File f2)
{
long l1 = getFileCreationEpoch(f1);
long l2 = getFileCreationEpoch(f2);
return Long.valueOf(l1).compareTo(l2);
}
});
}
public static long getFileCreationEpoch(File file)
{
try {
BasicFileAttributes attr = Files.readAttributes(file.toPath(),
BasicFileAttributes.class);
return attr.creationTime().toInstant().toEpochMilli();
} catch (IOException e) {
throw new RuntimeException(file.getAbsolutePath(), e);
}
}
}

View File

@ -27,13 +27,15 @@ public class Main
public static void main(String[] args)
{
ImageFinder imgF = null;
for (int i = 0; i < args.length; i++) {
//System.out.println(i + ": " +args[i]);
//System.out.println(i + ": " +args[i]);
String value = args[i];
if (value.equals("-log")) {
System.out.println("Logging will be used");
System.out.println("Logging will be used!");
log = true;
}
@ -42,6 +44,7 @@ public class Main
if (args[i].equals("createDB")) {
modi = true;
System.out.println("[Modi] Index images and create DB");
} else {
modi = false;
System.out.println("[Modi] Copy or Link images");
@ -50,7 +53,7 @@ public class Main
if (value.equals("-r")) {
i++;
rootFolderPath = args[i];
rootFolderPath = args[i];
System.out.println("[rootFolderPath] " + rootFolderPath);
}
@ -66,12 +69,28 @@ public class Main
System.out.println("[outputPath] " + outputPath);
}
if (value.equals("-i")) {
i++;
if (args[i].equals("counter")) {
System.out.println("[Identify] Find images with counter");
imgF = new ImageFinderCounter(rootFolderPath);
} else {
System.out.println("[Identify] Find images with date and time");
imgF = new ImageFinderTimestamp(rootFolderPath);
}
}
if (value.equals("-n")) {
i++;
maxImgageCounter = Integer.parseInt(args[i]);
System.out.println("[maxImgageCounter] " + maxImgageCounter);
}
if (value.equals("-help")) {
System.out.println(
"-log -m createDB -r /home/hendrik/FTP/camera01/ -p /home/hendrik/Schreibtisch/ -o /home/hendrik/Schreibtisch/testeritis/ -n 83584");
@ -81,11 +100,12 @@ public class Main
}
//System.exit(1);
if (modi) {
long timeStart;
ImageFinder imgF = new ImageFinder(rootFolderPath);
DBController db = new DBController(projectPath);
Exif exif = new Exif();
@ -97,15 +117,16 @@ public class Main
imgF.findYears(yearCount, startyear);
imgF.findMonths(yearCount);
if(log = true) {
if (log = true) {
imgF.printFoundDirectories();
}
timeStart = System.currentTimeMillis();
System.out.println("Suche ...");
//System.exit(1);
try {
PrintWriter missingTxt = new PrintWriter(
projectPath + "missingImages.txt");
@ -113,14 +134,14 @@ public class Main
float multiplicator = (float) (100.0 / maxImgageCounter);
System.out.println("Multiplicator: " + multiplicator);
for (int i = 0; i <= maxImgageCounter; i++) {
if(log == true) {
if (log == true) {
float percent = multiplicator * i;
System.out.print(i + "/" + maxImgageCounter + " --> ");
System.out.printf("%.2f", percent);
System.out.println("%");
}
String path = imgF.getImagePath(i);
// System.out.println(i + " Path: " + path);
System.out.println(i + " Path: " + path);
if (path != "404") {
// gefunden
File f = new File(rootFolderPath + path);
@ -148,18 +169,19 @@ public class Main
* 0.001);
System.out.println("Process time: " + processingTime + " seconds.");
} else {
System.out.println("Troll");
///////////////////////////////////////////////////////////////////
DBController db = new DBController(projectPath);
db.connectDatabase();
QueryImages qi = new QueryImages(db, outputPath, rootFolderPath);
//qi.outputImagesFromHour(0, 18, "copy", true);
//qi.outputImagesFromHourToHour(0, 8, 19, "copy", false);
// qi.outputImagesFromHour(0, 18, "copy", true);
// qi.outputImagesFromHourToHour(0, 8, 19, "copy", false);
qi.outputImagesEveryHour(0, 8, 19, "copy", false);
//qi.outputImagesFromHourAndMinute(40177, 8, 30, "copy", true);
// qi.outputImagesFromHourAndMinute(40177, 8, 30, "copy", true);
// qi.outputImagesFromStartToEnd(16185, 16282, 10, "copy", false,
// 2000000);