1
Fork 0

Exercici 3: Accés a les dades [40%]

This commit is contained in:
Guillem 2021-10-24 17:12:56 +02:00
parent 19613287e6
commit 058bd3dbaf
14 changed files with 119 additions and 40 deletions

View file

@ -1,8 +1,8 @@
.PHONY: clean All .PHONY: clean All
All: All:
@echo "----------Building project:[ UOC20211 - Release ]----------" @echo "----------Building project:[ UOC20211 - Debug ]----------"
@"$(MAKE)" -f "UOC20211.mk" @"$(MAKE)" -f "UOC20211.mk"
clean: clean:
@echo "----------Cleaning project:[ UOC20211 - Release ]----------" @echo "----------Cleaning project:[ UOC20211 - Debug ]----------"
@"$(MAKE)" -f "UOC20211.mk" clean @"$(MAKE)" -f "UOC20211.mk" clean

View file

@ -2,12 +2,12 @@
## Auto Generated makefile by CodeLite IDE ## Auto Generated makefile by CodeLite IDE
## any manual changes will be erased ## any manual changes will be erased
## ##
## Release ## Debug
ProjectName :=UOC20211 ProjectName :=UOC20211
ConfigurationName :=Release ConfigurationName :=Debug
WorkspacePath :=/dades/git/UOC/PP/PR1/UOC20211 WorkspacePath :=/dades/git/UOC/PP/PR1/UOC20211
ProjectPath :=/dades/git/UOC/PP/PR1/UOC20211 ProjectPath :=/dades/git/UOC/PP/PR1/UOC20211
IntermediateDirectory :=./bin/Release IntermediateDirectory :=./bin/Debug
OutDir := $(IntermediateDirectory) OutDir := $(IntermediateDirectory)
CurrentFileName := CurrentFileName :=
CurrentFilePath := CurrentFilePath :=
@ -27,8 +27,8 @@ OutputSwitch :=-o
LibraryPathSwitch :=-L LibraryPathSwitch :=-L
PreprocessorSwitch :=-D PreprocessorSwitch :=-D
SourceSwitch :=-c SourceSwitch :=-c
OutputFile :=./bin/$(ProjectName) OutputFile :=./bin/$(ProjectName)d
Preprocessors :=$(PreprocessorSwitch)NDEBUG Preprocessors :=
ObjectSwitch :=-o ObjectSwitch :=-o
ArchiveOutputSwitch := ArchiveOutputSwitch :=
PreprocessOnlySwitch :=-E PreprocessOnlySwitch :=-E
@ -39,8 +39,8 @@ LinkOptions :=
IncludePath := $(IncludeSwitch). $(IncludeSwitch). $(IncludeSwitch)test/include $(IncludeSwitch)UOCContacts/include IncludePath := $(IncludeSwitch). $(IncludeSwitch). $(IncludeSwitch)test/include $(IncludeSwitch)UOCContacts/include
IncludePCH := IncludePCH :=
RcIncludePath := RcIncludePath :=
Libs := $(LibrarySwitch)UOCContacts Libs := $(LibrarySwitch)UOCContactsd
ArLibs := "libUOCContacts.a" ArLibs := "libUOCContactsd.a"
LibPath := $(LibraryPathSwitch). $(LibraryPathSwitch)./lib LibPath := $(LibraryPathSwitch). $(LibraryPathSwitch)./lib
## ##
@ -50,8 +50,8 @@ LibPath := $(LibraryPathSwitch). $(LibraryPathSwitch)./lib
AR := /usr/bin/ar rcu AR := /usr/bin/ar rcu
CXX := /usr/bin/g++ CXX := /usr/bin/g++
CC := /usr/bin/gcc CC := /usr/bin/gcc
CXXFLAGS := -O2 -Wall $(Preprocessors) CXXFLAGS := -g -O0 -Wall $(Preprocessors)
CFLAGS := -O2 -Wall $(Preprocessors) CFLAGS := -g -O0 -Wall $(Preprocessors)
ASFLAGS := ASFLAGS :=
AS := /usr/bin/as AS := /usr/bin/as
@ -79,11 +79,11 @@ $(OutputFile): $(IntermediateDirectory)/.d $(Objects)
$(LinkerName) $(OutputSwitch)$(OutputFile) @$(ObjectsFileList) $(LibPath) $(Libs) $(LinkOptions) $(LinkerName) $(OutputSwitch)$(OutputFile) @$(ObjectsFileList) $(LibPath) $(Libs) $(LinkOptions)
MakeIntermediateDirs: MakeIntermediateDirs:
@test -d ./bin/Release || $(MakeDirCommand) ./bin/Release @test -d ./bin/Debug || $(MakeDirCommand) ./bin/Debug
$(IntermediateDirectory)/.d: $(IntermediateDirectory)/.d:
@test -d ./bin/Release || $(MakeDirCommand) ./bin/Release @test -d ./bin/Debug || $(MakeDirCommand) ./bin/Debug
PreBuild: PreBuild:
@ -121,6 +121,6 @@ $(IntermediateDirectory)/src_main.c$(PreprocessSuffix): src/main.c
## Clean ## Clean
## ##
clean: clean:
$(RM) -r ./bin/Release/ $(RM) -r ./bin/Debug/

View file

@ -1 +1 @@
./bin/Debug/test_src_test.c.o ./bin/Debug/test_src_test_suite.c.o ./bin/Debug/test_src_test_pr1.c.o ./bin/Debug/src_main.c.o ./bin/Release/test_src_test.c.o ./bin/Release/test_src_test_suite.c.o ./bin/Release/test_src_test_pr1.c.o ./bin/Release/src_main.c.o

View file

@ -3,12 +3,12 @@
<Project Name="UOC20211" Path="UOC20211.project" Active="Yes"/> <Project Name="UOC20211" Path="UOC20211.project" Active="Yes"/>
<Project Name="UOCContacts" Path="UOCContacts/UOCContacts.project"/> <Project Name="UOCContacts" Path="UOCContacts/UOCContacts.project"/>
<BuildMatrix> <BuildMatrix>
<WorkspaceConfiguration Name="Debug" Selected="no"> <WorkspaceConfiguration Name="Debug" Selected="yes">
<Environment/> <Environment/>
<Project Name="UOC20211" ConfigName="Debug"/> <Project Name="UOC20211" ConfigName="Debug"/>
<Project Name="UOCContacts" ConfigName="Debug"/> <Project Name="UOCContacts" ConfigName="Debug"/>
</WorkspaceConfiguration> </WorkspaceConfiguration>
<WorkspaceConfiguration Name="Release" Selected="yes"> <WorkspaceConfiguration Name="Release" Selected="no">
<Environment/> <Environment/>
<Project Name="UOC20211" ConfigName="Release"/> <Project Name="UOC20211" ConfigName="Release"/>
<Project Name="UOCContacts" ConfigName="Release"/> <Project Name="UOCContacts" ConfigName="Release"/>

View file

@ -2,12 +2,12 @@
## Auto Generated makefile by CodeLite IDE ## Auto Generated makefile by CodeLite IDE
## any manual changes will be erased ## any manual changes will be erased
## ##
## Release ## Debug
ProjectName :=UOCContacts ProjectName :=UOCContacts
ConfigurationName :=Release ConfigurationName :=Debug
WorkspacePath :=/dades/git/UOC/PP/PR1/UOC20211 WorkspacePath :=/dades/git/UOC/PP/PR1/UOC20211
ProjectPath :=/dades/git/UOC/PP/PR1/UOC20211/UOCContacts ProjectPath :=/dades/git/UOC/PP/PR1/UOC20211/UOCContacts
IntermediateDirectory :=../bin/Release IntermediateDirectory :=../bin/Debug
OutDir := $(IntermediateDirectory) OutDir := $(IntermediateDirectory)
CurrentFileName := CurrentFileName :=
CurrentFilePath := CurrentFilePath :=
@ -27,7 +27,7 @@ OutputSwitch :=-o
LibraryPathSwitch :=-L LibraryPathSwitch :=-L
PreprocessorSwitch :=-D PreprocessorSwitch :=-D
SourceSwitch :=-c SourceSwitch :=-c
OutputFile :=../lib/lib$(ProjectName).a OutputFile :=../lib/lib$(ProjectName)d.a
Preprocessors := Preprocessors :=
ObjectSwitch :=-o ObjectSwitch :=-o
ArchiveOutputSwitch := ArchiveOutputSwitch :=
@ -50,8 +50,8 @@ LibPath := $(LibraryPathSwitch).
AR := /usr/bin/ar rcu AR := /usr/bin/ar rcu
CXX := /usr/bin/g++ CXX := /usr/bin/g++
CC := /usr/bin/gcc CC := /usr/bin/gcc
CXXFLAGS := $(Preprocessors) CXXFLAGS := -g $(Preprocessors)
CFLAGS := $(Preprocessors) CFLAGS := -g $(Preprocessors)
ASFLAGS := ASFLAGS :=
AS := /usr/bin/as AS := /usr/bin/as
@ -77,15 +77,15 @@ $(OutputFile): $(Objects)
@echo "" > $(IntermediateDirectory)/.d @echo "" > $(IntermediateDirectory)/.d
@echo $(Objects0) > $(ObjectsFileList) @echo $(Objects0) > $(ObjectsFileList)
$(AR) $(ArchiveOutputSwitch)$(OutputFile) @$(ObjectsFileList) $(AR) $(ArchiveOutputSwitch)$(OutputFile) @$(ObjectsFileList)
@$(MakeDirCommand) "/dades/git/UOC/PP/PR1/UOC20211/.build-release" @$(MakeDirCommand) "/dades/git/UOC/PP/PR1/UOC20211/.build-debug"
@echo rebuilt > "/dades/git/UOC/PP/PR1/UOC20211/.build-release/UOCContacts" @echo rebuilt > "/dades/git/UOC/PP/PR1/UOC20211/.build-debug/UOCContacts"
MakeIntermediateDirs: MakeIntermediateDirs:
@test -d ../bin/Release || $(MakeDirCommand) ../bin/Release @test -d ../bin/Debug || $(MakeDirCommand) ../bin/Debug
../bin/Release: ../bin/Debug:
@test -d ../bin/Release || $(MakeDirCommand) ../bin/Release @test -d ../bin/Debug || $(MakeDirCommand) ../bin/Debug
PreBuild: PreBuild:
@ -129,6 +129,6 @@ $(IntermediateDirectory)/src_date.c$(PreprocessSuffix): src/date.c
## Clean ## Clean
## ##
clean: clean:
$(RM) -r ../bin/Release/ $(RM) -r ../bin/Debug/

View file

@ -1 +1 @@
../bin/Debug/src_contact.c.o ../bin/Debug/src_api.c.o ../bin/Debug/src_person.c.o ../bin/Debug/src_csv.c.o ../bin/Debug/src_date.c.o ../bin/Release/src_contact.c.o ../bin/Release/src_api.c.o ../bin/Release/src_person.c.o ../bin/Release/src_csv.c.o ../bin/Release/src_date.c.o

View file

@ -85,5 +85,4 @@ void timePos_cpy(tTimePosition* destination, tTimePosition source);
// Clear tGeopositionData structure // Clear tGeopositionData structure
void geoData_free(tGeolocationData* geoData); void geoData_free(tGeolocationData* geoData);
//////////////////////////////////////////// ////////////////////////////////////////////
#endif #endif

View file

@ -165,7 +165,32 @@ tApiError api_findPerson(tApiData* data, const char* document, tCSVEntry* person
////////////////////////////////// //////////////////////////////////
// Ex PR1 3 // Ex PR1 3
///////////////////////////////// /////////////////////////////////
return E_NOT_IMPLEMENTED;
// Init new person entry for CSV data storage
csv_initEntry(person);
int index = population_find(data->population, document);
if (index != -1) {
char strCSV[FILE_READ_BUFFER_SIZE];
tPerson found = data->population.elems[index];
// Fill strCSV variable with data from the person found
sprintf(strCSV, "%s;%s;%s;%s;%s;%s;%s;%d/%d/%d",
"PERSON", found.document, found.name, found.surname,
found.email, found.address, found.cp,
found.birthday.day, found.birthday.month, found.birthday.year);
csv_parseEntry(person, strCSV, NULL);
return E_SUCCESS;
} else {
return E_PERSON_NOT_FOUND;
}
} }
// Get all geolocation data for a given person // Get all geolocation data for a given person
@ -173,7 +198,37 @@ tApiError api_getPersonGeolocation(tApiData* data, const char* document, tCSVDat
////////////////////////////////// //////////////////////////////////
// Ex PR1 3 // Ex PR1 3
///////////////////////////////// /////////////////////////////////
return E_NOT_IMPLEMENTED;
assert(geodata != NULL);
tApiError ret;
csv_init(geodata);
int i;
for(i = 0; i < data->geolocationData.count; i++) {
if(strcmp(data->geolocationData.elems[i].person, document) == 0) {
tTimePosition found = data->geolocationData.elems[i];
tCSVEntry csvEntry;
char strCSV[FILE_READ_BUFFER_SIZE];
// Fill strCSV variable with data from the person found
sprintf(strCSV, "%s;%s;%d/%d/%d;%d:%d;%f;%f",
"GEOLOCATION", found.person,
found.timestamp.date.day, found.timestamp.date.month, found.timestamp.date.year,
found.timestamp.time.hour, found.timestamp.time.minutes,
found.coordinate.latitude, found.coordinate.longitude);
csv_addStrEntry(geodata, strCSV, NULL);
}
}
if (geodata->count != 0) {
return E_SUCCESS;
} else {
return E_PERSON_NOT_FOUND;
}
} }
// Remove a person // Remove a person
@ -181,5 +236,31 @@ tApiError api_removePerson(tApiData* data, const char* document) {
////////////////////////////////// //////////////////////////////////
// Ex PR1 3 // Ex PR1 3
///////////////////////////////// /////////////////////////////////
return E_NOT_IMPLEMENTED;
population_del(&data->population, document);
tCSVData toDelete;
tDateTime dateTime;
char date[11];
char time[6];
api_getPersonGeolocation(data, document, &toDelete);
for(int i = 0; i < toDelete.count; i++) {
csv_getAsString(toDelete.entries[i], 1, date, 11);
csv_getAsString(toDelete.entries[i], 2, time, 6);
dateTime_parse(&dateTime, date, time);
geoData_del(&data->geolocationData, document, dateTime);
}
if (toDelete.count != 0) {
return E_SUCCESS;
} else {
return E_PERSON_NOT_FOUND;
}
} }

View file

@ -5,7 +5,7 @@
#include "contact.h" #include "contact.h"
// Parse a tDateTime from string information // Parse a tDateTime from string information
void dateTime_parse(tDateTime* dateTime, const char* date, const char* time) { /*void dateTime_parse(tDateTime* dateTime, const char* date, const char* time) {
// Check output data // Check output data
assert(dateTime != NULL); assert(dateTime != NULL);
@ -22,16 +22,16 @@ void dateTime_parse(tDateTime* dateTime, const char* date, const char* time) {
// Parse the input time // Parse the input time
sscanf(time, "%d:%d", &(dateTime->time.hour), &(dateTime->time.minutes)); sscanf(time, "%d:%d", &(dateTime->time.hour), &(dateTime->time.minutes));
} }*/
// Compare two tDateTime structures and return true if they contain the same value or false otherwise. // Compare two tDateTime structures and return true if they contain the same value or false otherwise.
bool dateTime_cmp(tDateTime dateTime1, tDateTime dateTime2) { /*bool dateTime_cmp(tDateTime dateTime1, tDateTime dateTime2) {
if (dateTime1.date.day != dateTime2.date.day || dateTime1.date.month != dateTime2.date.month || dateTime1.date.year != dateTime2.date.year) { if (dateTime1.date.day != dateTime2.date.day || dateTime1.date.month != dateTime2.date.month || dateTime1.date.year != dateTime2.date.year) {
return false; return false;
} }
return dateTime1.time.hour == dateTime2.time.hour && dateTime1.time.minutes == dateTime2.time.minutes; return dateTime1.time.hour == dateTime2.time.hour && dateTime1.time.minutes == dateTime2.time.minutes;
} }*/
// EX2: Implement your methods here.... // EX2: Implement your methods here....

Binary file not shown.

Binary file not shown.

View file

@ -7,4 +7,3 @@
-I/dades/git/UOC/PP/PR1/UOC20211 -I/dades/git/UOC/PP/PR1/UOC20211
-I/dades/git/UOC/PP/PR1/UOC20211/test/include -I/dades/git/UOC/PP/PR1/UOC20211/test/include
-I/dades/git/UOC/PP/PR1/UOC20211/UOCContacts/include -I/dades/git/UOC/PP/PR1/UOC20211/UOCContacts/include
-DNDEBUG

Binary file not shown.

Binary file not shown.