Skip to content

Commit

Permalink
Merge pull request #1 from datascience/feature/UI-conflicts
Browse files Browse the repository at this point in the history
Feature/UI conflicts
  • Loading branch information
artourkin authored Oct 23, 2023
2 parents 06adf43 + 85829c2 commit 7be5a4c
Show file tree
Hide file tree
Showing 17 changed files with 138 additions and 10 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ Place where your FITS files feel good

Content Profiling revisited


# Local build

docker-compose -f docker-compose.dev.yaml up --build


File uploading using bash:

bash fileupload.sh http://localhost:8082 ~/rnd/data/govdocs_fits/govdocs1/000/


Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
public interface GetCollectionStatistics {
Map<String, Object> getSizeStatistics();

Double getConflictRate();
double getConflictRate();
}
2 changes: 2 additions & 0 deletions core/src/main/java/rocks/artur/api/GetObjects.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@
public interface GetObjects {
List<PropertiesPerObjectStatistic> getObjects(FilterCriteria filterCriteria);
Iterable<CharacterisationResult> getObject(String filePath);

List<CharacterisationResult> getConflictsFromObject(String filePath);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public Map<String, Object> getSizeStatistics() {
}

@Override
public Double getConflictRate() {
return 17.0;
public double getConflictRate() {
return characterisationResultGateway.getConflictRate();
}
}
8 changes: 8 additions & 0 deletions core/src/main/java/rocks/artur/api_impl/GetObjectsImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,12 @@ public Iterable<CharacterisationResult> getObject(String filePath) {
Iterable<CharacterisationResult> characterisationResultsByFilepath = characterisationResultGateway.getCharacterisationResultsByFilepath(filePath);
return characterisationResultsByFilepath;
}

@Override
public List<CharacterisationResult> getConflictsFromObject(String filePath) {
List<CharacterisationResult> characterisationResultsByFilepath = characterisationResultGateway.getConflictsByFilepath(filePath);
return characterisationResultsByFilepath;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ public interface CharacterisationResultGateway {
*/
List<CharacterisationResult> getCharacterisationResultsByFilepath(String filePath);

/**
* gets a list of characterisation results with conflicts for a given digital object.
*
* @return an iterable of characterisation results.
*/
List<CharacterisationResult> getConflictsByFilepath(String filepath);

Map<String, Object> getSizeStatistics();

List<PropertyValueStatistic> getPropertyValueDistribution(Property property, FilterCriteria<CharacterisationResult> filter);
Expand All @@ -68,4 +75,6 @@ public interface CharacterisationResultGateway {
List<String[]> getSamples(FilterCriteria filterCriteria, SamplingAlgorithms algorithm, List<Property> properties);

void addCharacterisationResults(List<CharacterisationResult> characterisationResults);

double getConflictRate();
}
12 changes: 9 additions & 3 deletions docker-compose.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ version: '3'
services:

fits:
build: ./fits/
build:
context: .
dockerfile: ./fits/Dockerfile
container_name: fits
env_file: .env
networks:
Expand All @@ -14,7 +16,9 @@ services:

rest:
container_name: rest
build: ./
build:
context: .
dockerfile: ./Dockerfile
env_file: .env
networks:
- web
Expand All @@ -26,7 +30,9 @@ services:
- db-docker

web:
build: ./web/
build:
context: .
dockerfile: ./web/Dockerfile
container_name: web
env_file: .env
networks:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import rocks.artur.domain.statistics.PropertyValueStatistic;
import rocks.artur.jpa.table.CharacterisationResultJPA;
import rocks.artur.jpa.table.CharacterisationResultRepository;
import rocks.artur.jpa.view.CharacterisationResultViewJPA;
import rocks.artur.jpa.view.CharacterisationResultViewRepository;

import java.util.Comparator;
Expand Down Expand Up @@ -117,6 +118,14 @@ public List<CharacterisationResult> getCharacterisationResultsByFilepath(String
return result;
}


public List<CharacterisationResult> getConflictsByFilepath(String filepath) {
List<CharacterisationResultViewJPA> allJPAByFilePath = characterisationResultViewRepository.findAllByFilePath(filepath);
List<CharacterisationResult> result = allJPAByFilePath.stream().filter(item -> item.getValue().equals("CONFLICT")).map(item -> new CharacterisationResult(Property.valueOf(item.getProperty()), item.getValue(),
ValueType.valueOf(item.getValueType()), null, item.getFilePath())).collect(Collectors.toList());
return result;
}

@Override
public Map<String, Object> getSizeStatistics() {
Map<String, Object> result = new HashMap<>();
Expand All @@ -134,6 +143,9 @@ public Map<String, Object> getSizeStatistics() {
Long totalCount = characterisationResultViewRepository.getTotalCount();
result.put("totalCount", totalCount);

Long conflictRate = characterisationResultViewRepository.getConflictCount();
result.put("conflictRate", conflictRate);

List<Object[]> sizeDistribution = characterisationResultViewRepository.getSizeDistribution();

List<PropertyValueStatistic> collect = sizeDistribution.stream()
Expand Down Expand Up @@ -200,4 +212,11 @@ public void addCharacterisationResults(List<CharacterisationResult> characterisa
LOG.debug("saving " + collect);
characterisationResultRepository.saveAll(collect);
}

@Override
public double getConflictRate() {
Long totalCount = characterisationResultViewRepository.getTotalCount();
Long conflictCount = characterisationResultViewRepository.getConflictCount();
return conflictCount/(double)totalCount;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
public interface CustomCharacterisationResultRepository {

void saveFast(List<CharacterisationResultJPA> results);


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import rocks.artur.jpa.table.CharacterisationResultJPA;

import java.util.List;

Expand All @@ -13,7 +14,10 @@ public interface CharacterisationResultViewRepository extends JpaRepository<Char
@Query("select property, count(*) as count from CharacterisationResultViewJPA group by property")
List<Object[]> getPropertyDistribution();

@Query("select count(*) as count from CharacterisationResultViewJPA where value='CONFLICT'")
Long getConflictCount();

List<CharacterisationResultViewJPA> findAllByFilePath(String filePath);



Expand Down
12 changes: 12 additions & 0 deletions infra-rest/src/main/java/rocks/artur/endpoints/RestService.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.text.ParseException;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
@CrossOrigin
Expand Down Expand Up @@ -84,6 +85,17 @@ public Iterable<CharacterisationResult> getObject(
return objects;
}

@RequestMapping(method = RequestMethod.POST, value = "/objectconflicts")
@Consumes(MediaType.APPLICATION_JSON)
public List<Property> getConflictsPerObject(
@RequestParam(name = "filepath", required = true) @Parameter(name = "filepath", description = "Filepath of a digital object", example = "/home/user/file1") String filepath) {
List<CharacterisationResult> objects = getObjects.getConflictsFromObject(filepath);
List<Property> collect = objects.stream().map(item -> item.getProperty()).collect(Collectors.toList());
return collect;
}




@RequestMapping(method = RequestMethod.GET, value = "/statistics")
public Map<String, Object> getCollectionStatistics() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ void getCharacterisationResultsByFilepathTest() {
void getCollectionStatisticsTest() {
Map<String, Object> sizeStatistics = characterisationResultGatewaySqlImpl.getSizeStatistics();
Assert.assertEquals(10047L, Long.valueOf(sizeStatistics.get("totalSize").toString()).longValue());
System.out.println(sizeStatistics);
}


Expand All @@ -114,4 +115,11 @@ void getSFDSamplesTest() {
List<String[]> samples = characterisationResultGatewaySqlImpl.getSamples(null, SamplingAlgorithms.SELECTIVE_FEATURE_DISTRIBUTION, properties);
Assert.assertEquals(2, samples.size());
}

@Test
void getConflictRateTest() {

double conflictRate = characterisationResultGatewaySqlImpl.getConflictRate();
Assert.assertEquals(0.333333333333,conflictRate, 0.01);
}
}
10 changes: 10 additions & 0 deletions main/src/test/java/rocks/artur/RestServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,16 @@ void getObjectsTest() {
System.out.println("Result: " + str);
}

@Test
void getObjectConflictsTest() {
String str = given().port(port).param("filepath","/home/artur/file1")
.when().post("/objectconflicts")
.then()
.statusCode(200).extract().asString();
System.out.println("Result: " + str);
}


@Test
void getPropertyDistributionWithFilterTest() {
String str = given().port(port)
Expand Down
3 changes: 2 additions & 1 deletion web/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
FROM node:14.5.0-stretch-slim


WORKDIR /app

WORKDIR /app
COPY ./web/frontend ./

RUN npm install
RUN npm run build

Expand Down
8 changes: 7 additions & 1 deletion web/frontend/src/components/Table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { tokens } from "../theme";

import { useTheme } from "@mui/material";

const Table = ({ data, columns, initialState, onRowClick }) => {
const Table = ({ data, columns, initialState, onRowClick, rowFunction }) => {
const theme = useTheme();
const colors = tokens(theme.palette.mode);

Expand Down Expand Up @@ -39,6 +39,10 @@ const Table = ({ data, columns, initialState, onRowClick }) => {
"& .MuiDataGrid-toolbarContainer .MuiButton-text": {
color: `${colors.grey[100]} !important`,
},
'& .conflict': {
backgroundColor: colors.redAccent[700],
color: colors.greenAccent[300],
},
}}
>
<DataGrid
Expand All @@ -47,6 +51,8 @@ const Table = ({ data, columns, initialState, onRowClick }) => {
columns={columns}
components={{ Toolbar: GridToolbar }}
initialState={initialState}

getRowClassName={rowFunction}
/>
</Box>
);
Expand Down
10 changes: 10 additions & 0 deletions web/frontend/src/scenes/dashboard/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const Dashboard = () => {
],
minSize: 4,
maxSize: 10000,
conflictRate: 0.17,
});

useEffect(() => {
Expand Down Expand Up @@ -99,6 +100,15 @@ const Dashboard = () => {
: (sizeStatistics.maxSize / 1024 / 1024).toFixed(2)
}
/>

<Stat
title="Conflct Rate (%)"
value={
sizeStatistics.conflictRate == null
? 0
: (sizeStatistics.conflictRate * 100).toFixed(2)
}
/>
</Grid2>
<Grid2 container spacing={1}>
<Histogram property="MIMETYPE"></Histogram>
Expand Down
27 changes: 25 additions & 2 deletions web/frontend/src/scenes/objectDetails/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,31 @@ const ObjectDetails = () => {
);
const data = await response.json();


const response2 = await fetch(
BACKEND_URL +
"/objectconflicts?" +
new URLSearchParams({
filepath: state.objectdetails,
}),
requestOptions
);
const conflictedProps = await response2.json();



let id = 0;
var tmp = data.map((stat) => {
var res = stat;
res.id = id++;
if (conflictedProps.includes(res.property)) {
res.conflict=true
}
return res;
});

console.log(tmp)
setData(tmp);

} catch (error) {
console.log(error);
}
Expand Down Expand Up @@ -88,14 +105,20 @@ const ObjectDetails = () => {
},
];


const rowFunction = (params) => {
return params.row.conflict ? 'conflict': '' ;
}


return (
<Box m="20px">
<Header
title="Object Details"
subtitle={"on: " + state.objectdetails}
></Header>
<Box height="75vh">
<Table data={data} columns={columns} initialState={initialState} />
<Table data={data} columns={columns} initialState={initialState} rowFunction={rowFunction}/>
</Box>
</Box>
);
Expand Down

0 comments on commit 7be5a4c

Please sign in to comment.