Skip to content

Commit

Permalink
Heatmap Model Implementation
Browse files Browse the repository at this point in the history
md5sum a.out
8191e56ee56845255c053bdc927a66b1  a.out

Created implementation of heatmap model. To be honest, I'm not happy
with name of the model, it's a piece of the heatmap so I want to call it
something better. Like heatzone, or heatpoint, or something. But I'm not
sure what I would call it. IntensitySpot? For now, heatmap works well.

Updated MakeFile to reflect new model file, and changed the linker to
just do *.o so I don't have to keep updating the linking portion. While
it does pay to be explicit about these things, I'm throwing everything
into one obj folder so it's not really a problem. I don't do any partial
compilation and linking either so all is good. Although it might be
interesting to try to do that.

Another thing to note is that the setId functions are all the same
really, same with setting scope Id. I don't think there's a way to do
inheritance in C (easily at least, function pointers?). But this would
be the time for it I guess. I wonder if doing it as a generic struct
with an id field and doing a cast would allow me to do it.
  • Loading branch information
EdgeCaseBerg committed Sep 27, 2013
1 parent 4144337 commit 549d76d
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#Make sure to compile with: $(mysql_config --cflags) and link to: $(mysql_config --libs)

a.out: gs.o
cc obj/db.o obj/gs.o obj/json.o obj/scope.o obj/comment.o obj/marker.o -o a.out -L/usr/lib/x86_64-linux-gnu -lmysqlclient -lpthread -lz -lm -lrt -ldl -g
cc obj/*o -o a.out -L/usr/lib/x86_64-linux-gnu -lmysqlclient -lpthread -lz -lm -lrt -ldl -g

gs.o: green-serv.c json.o db.o
cc -I./headers -std=gnu99 -pedantic -Wall -Wextra -Werror -g -c green-serv.c -o obj/gs.o

db.o: src/database/db.c scope.o comment.o marker.o
db.o: src/database/db.c scope.o comment.o marker.o heatmap.o
cc -I./headers -I/usr/include/mysql -DBIG_JOINS=1 -fno-strict-aliasing -std=gnu99 -pedantic -Wall -Wextra -Werror -g -c src/database/db.c -o obj/db.o

json.o: src/helpers/json.c comment.o scope.o marker.o
json.o: src/helpers/json.c comment.o scope.o marker.o heatmap.o
cc -I./headers -std=gnu99 -pedantic -Wall -Wextra -Werror -g -c src/helpers/json.c -o obj/json.o

scope.o: src/models/scope.c
Expand All @@ -21,5 +21,9 @@ comment.o: src/models/comment.c
marker.o: src/models/marker.c
cc -I./headers -std=gnu99 -pedantic -Wall -Wextra -Werror -g -c src/models/marker.c -o obj/marker.o

#Heatmap depends on marker for implementation of createDecimal
heatmap.o: src/models/heatmap.c marker.o
cc -I./headers -std=gnu99 -pedantic -Wall -Wextra -Werror -g -c src/models/heatmap.c -o obj/heatmap.o

clean:
rm obj/*.o *.out
4 changes: 4 additions & 0 deletions green-serv.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "flags.h"
#include "models/comment.h"
#include "models/marker.h"
#include "models/heatmap.h"
#include <string.h>


Expand All @@ -26,6 +27,7 @@ int main(int argc, const char* argv[]) {
struct gs_comment * commentPage;
struct gs_marker testMarker;
struct gs_marker * markerPage;
struct gs_heatmap testHeatmap;
Decimal latitude;
Decimal longitude;
char json[512];
Expand Down Expand Up @@ -114,6 +116,8 @@ int main(int argc, const char* argv[]) {
fprintf(stderr, "%s\n", "Could not allocate enough memory for marker page");
}

gs_heatmap_ZeroStruct(&testHeatmap);


/*Clean Up database connection*/
mysql_close(conn);
Expand Down
45 changes: 45 additions & 0 deletions src/models/heatmap.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <string.h>
#include "models/heatmap.h"

/* Any functions specifically working with just gs_marker: */
void gs_mheatmap_setId(long id, struct gs_heatmap * gsh){
gsh->id = id;
}

void gs_heatmap_setIntensity(long intensity, struct gs_heatmap * gsh){
gsh->intensity = intensity;
}

void gs_heatmap_setScopeId(long scopeId, struct gs_heatmap * gsh){
gsh->scopeId = scopeId;
}

/* Will truncate to 19 characters */
void gs_heatmap_setCreatedTime(char * createdTime, struct gs_heatmap * gsh){
strncpy(gsh->createdTime, createdTime, GS_HEATMAP_CREATED_TIME_LENGTH);
}

void gs_heatmap_setLongitude(Decimal longitude, struct gs_heatmap * gsh){
gsh->longitude = longitude;
}

void gs_heatmap_setLatitude(Decimal latitude, struct gs_heatmap * gsh){
gsh->latitude = latitude;
}


/* Empties a marker structure of data and sets flag values */
void gs_heatmap_ZeroStruct(struct gs_heatmap * gsh){
bzero(gsh->createdTime, GS_HEATMAP_CREATED_TIME_LENGTH+1);
gsh->id = GS_HEATMAP_INVALID_ID;
gsh->intensity = 0;
/* 0 is actually a good 'invalid' or default for the right
* side because if someone gives just 1. or 1 to a string
* parsing function and we only set the left, the right is
* still correct!
*/
gsh->longitude.left = 0;
gsh->longitude.right = 0;
gsh->latitude.left = 0;
gsh->latitude.right = 0;
}

0 comments on commit 549d76d

Please sign in to comment.