Skip to content

Commit

Permalink
Shortname for preachers (wip), Statistic one year
Browse files Browse the repository at this point in the history
  • Loading branch information
hydrogen2oxygen committed Dec 21, 2023
1 parent 821739c commit d34dbed
Show file tree
Hide file tree
Showing 9 changed files with 196 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public class Preacher implements Serializable {

private String name;

private String shortName;

private Boolean softdelete = false;

private Boolean harddelete = false;
Expand Down Expand Up @@ -52,6 +54,14 @@ public void setName(String name) {
this.name = name;
}

public String getShortName() {
return shortName;
}

public void setShortName(String shortName) {
this.shortName = shortName;
}

public List<String> getGroup() {
return group;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import de.pietro.lusso.territory.domain.osm.OsmStreet;
import de.pietro.lusso.territory.services.mapDesign.MapDesignService;
import de.pietro.lusso.territory.utils.EncryptionTool;
import de.pietro.lusso.territory.utils.PreacherUtils;
import de.pietro.lusso.territory.utils.SettingsInitializer;
import de.pietro.lusso.territory.utils.ZipUtility;
import org.apache.commons.io.FileUtils;
Expand Down Expand Up @@ -314,15 +315,22 @@ private Congregation enhanceCongregationData(Congregation congregation) throws I
Map<String, Preacher> preacherMap = new HashMap<>();

boolean congregationExist = false;
int i = 1;

// ... use only to reset congregation.getPreacherList().forEach(preacher -> preacher.setShortName(null));
PreacherUtils.setShortNames(congregation.getPreacherList());

for (Preacher preacher : congregation.getPreacherList()) {

if (StringUtils.isEmpty(preacher.getName())) {
preacher.setName("EMPTY_" + i++);
}

if (Congregation.CONGREGATION.equals(preacher.getName())) {
congregationExist = true;
}

preacher.getTerritoryListNumbers().clear();
if (preacher.getName() == null || preacher.getName().trim().length() == 0) continue;
preacherMap.put(preacher.getName(), preacher);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package de.pietro.lusso.territory.utils;

import de.pietro.lusso.territory.domain.Congregation;
import de.pietro.lusso.territory.domain.Preacher;
import org.apache.commons.lang3.StringUtils;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class PreacherUtils {

private PreacherUtils(){}

public static void setShortNames(final List<Preacher> preacherList) {

Set<String> names = new HashSet<>();
int i = 0;
preacherList.sort((o1, o2) -> o1.getName().compareTo(o2.getName()));

for (Preacher preacher : preacherList) {
if (StringUtils.isNotEmpty(preacher.getShortName())) {
names.add(preacher.getShortName());
}
}

String previousShortName = null;

for (Preacher preacher : preacherList) {

String shortName = getShortName(preacher);

if (!shortName.equals(previousShortName)) {
i = 0;
previousShortName = shortName;
}

if (StringUtils.isNotEmpty(preacher.getShortName())) {
i = 0;
continue;
}

if (names.contains(shortName)) {
i++;
names.add(shortName + i);
preacher.setShortName(shortName + i);
} else {
i = 0;
names.add(shortName);
preacher.setShortName(shortName);
}
}
}

private static String getShortName(Preacher preacher) {

String [] parts = preacher.getName().split(" ");
StringBuilder shortName = new StringBuilder();

for (String part : parts) {
try {
int maxLength = 2;
if (part.length() < maxLength) continue;
shortName.append(part.substring(0,maxLength));
} catch (Exception e) {
e.printStackTrace();
}
}

return shortName.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export class AppComponent {

constructor(
private router: Router,

private route: ActivatedRoute,
private congregationService:CongregationService,
private navigationService:NavigationService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,24 @@ <h1 style="color: darkorange" *ngIf="loading">... please wait ... processing ...
*ngFor="let p of congregation.preacherList"
(click)="openPreacher(p)"
data-bs-toggle="modal" data-bs-target="#preacherDetailsModal">
{{p.name}} <span *ngIf="p.territoryListNumbers.length > 0">({{p.territoryListNumbers.length}})</span>
{{p.name}}
<span *ngIf="p.territoryListNumbers.length > 0">({{p.territoryListNumbers.length}})</span>
</button>
</div>
<hr>
<div style="width: 50%">
<table class="table table-bordered table-sm table-striped table-dark">
<thead>
<tr><th>SHORT</th><th>NAME</th></tr>
</thead>
<tbody>
<tr *ngFor="let p of congregation.preacherList">
<td>{{p.shortName}}</td>
<td>{{p.name}}</td>
</tr>
</tbody>
</table>
</div>

Preachers {{
congregation.preacherList.length
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ <h4 class="collapseHeader" data-bs-toggle="collapse" href="#sorted" role="button
+ congregation.territoriesOlder4Months.length
+ congregation.territoriesOlder8Months.length
+ congregation.territoriesToBeAssigned.length
}}
}} | visited during one year {{visitedDuringLastYear}} | not visited for one year {{notVisitedForOneYear}}
<hr>
<button class="btn btn-sm btn-success" (click)="printPDF()">PRINT PDF</button>
<button *ngIf="congregation.counterFtpUploadFailed > 0" class="btn btn-sm btn-danger" style="margin-left: 0.5rem; font-weight: bolder" (click)="repairFtpUploads()">REPAIR FTP UPLOADS <i class="bi bi-cloud-slash" style="margin-left: 0.25rem"></i> {{congregation.counterFtpUploadFailed}} failed uploads</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export class TerritoriesComponent implements OnInit {
preacherList: Preacher[] = [];
selectedPreacher: any = null;
keyword: string = "name";
visitedDuringLastYear:number = 0
notVisitedForOneYear:number = 0

noContacts = new FormControl(false);
intoArchive = new FormControl(false);
Expand Down Expand Up @@ -85,9 +87,46 @@ export class TerritoriesComponent implements OnInit {
this.territoriesSorted = this.territoriesSorted.concat(c.territoriesOlder4Months);

this.territoriesSorted = this.territoriesSorted.sort((a, b) => (a.number > b.number ? 1 : -1));

setTimeout(()=>{
this.visitedDuringLastYear = 0
this.notVisitedForOneYear = 0

let oneYearDate:Date = new Date()
oneYearDate.setFullYear(oneYearDate.getFullYear() - 1);

this.territoriesSorted.forEach(t => {
let registryExist:boolean = false
t.registryEntryList.forEach( r => {
if (r.returnDate) {
if (this.parseDateString(r.returnDate) > oneYearDate) {
registryExist = true
}
}
})

if (registryExist) this.visitedDuringLastYear = this.visitedDuringLastYear + 1
})

this.notVisitedForOneYear = this.congregation.territoriesAssigned.length
+ this.congregation.territoriesNoContacts.length
+ this.congregation.territoriesOlder4Months.length
+ this.congregation.territoriesOlder8Months.length
+ this.congregation.territoriesToBeAssigned.length
- this.visitedDuringLastYear;

},1)
});
}

parseDateString(dateString: any): Date {
if (dateString instanceof Date) {
return dateString;
}
return new Date(dateString);
}


showTerritoryDetails(territory: Territory) {
console.log(territory)
this.territory = territory;
Expand Down
1 change: 1 addition & 0 deletions server/src/main/ui2/src/app/domains/Congregation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class Congregation {

export class Preacher {
name:string = '';
shortName:string | undefined;

uuid:string = '';
territoryListNumbers:string[] = [];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package de.pietro.lusso.territory.utils;

import de.pietro.lusso.territory.domain.Preacher;
import org.junit.Assert;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

public class PreacherUtilsTest {

@Test
public void testSimilarNames() {
List<Preacher> list = new ArrayList<>();
Preacher p0 = new Preacher();
p0.setName("Jim Maria");
Preacher p1 = new Preacher();
p1.setName("John Dude");
Preacher p2 = new Preacher();
p2.setName("John Duo");
Preacher p3 = new Preacher();
p3.setName("John Dual");
Preacher p4 = new Preacher();
p4.setName("John Maria");
Preacher p5 = new Preacher();
p5.setName("John Maria");
p5.setShortName("JoMa");
list.add(p0);
list.add(p1);
list.add(p2);
list.add(p3);
list.add(p4);
list.add(p5);

PreacherUtils.setShortNames(list);

for (Preacher preacher : list) {
System.out.println(preacher.getShortName());
}

Assert.assertEquals("JiMa", list.get(0).getShortName());
Assert.assertEquals("JoDu", list.get(1).getShortName());
Assert.assertEquals("JoDu1", list.get(2).getShortName());
Assert.assertEquals("JoDu2", list.get(3).getShortName());
Assert.assertEquals("JoMa1", list.get(4).getShortName());
Assert.assertEquals("JoMa", list.get(5).getShortName());
}
}

0 comments on commit d34dbed

Please sign in to comment.