Skip to content

Commit

Permalink
Theme switched to guzzle_sphinx_theme.
Browse files Browse the repository at this point in the history
  • Loading branch information
vbotka committed Jan 6, 2018
1 parent 49d7dc0 commit 25aad55
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 25 deletions.
22 changes: 9 additions & 13 deletions docs/source/code/create-graph-01.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
#include <hiredis.h>

#define RCMD(context, ...) { \
freeReplyObject(reply); \
reply = redisCommand(context, __VA_ARGS__); \
assert(reply != NULL); \
freeReplyObject(reply); \
}

const char LOG_SEPARATOR = ' ';
Expand All @@ -22,9 +22,9 @@ const char *LOG_FILES[] = { "dpkg.log", };

redisContext *c;

// This function reads log_file and puts the status into the database.
/* This function reads log_file and puts the status into the database.*/
int read_log(const char *log_file, redisContext *c) {
redisReply *reply;
redisReply *reply=NULL;
FILE *fp;
char line[256];
char *p, *date, *status;
Expand All @@ -46,32 +46,30 @@ int read_log(const char *log_file, redisContext *c) {
return(0);
}

// This function reads the database and writes the status CSV file.
/* This function reads the database and writes the status CSV file. */
int write_csv(char *status, redisContext *c) {
redisReply *reply;
redisReply *reply=NULL;
FILE *fp;
int i,n;
char filename[256];

strcpy(filename, status);
strcat(filename, ".csv");
fp = fopen(filename, "w");
reply = redisCommand(c, "ZRANGE %s 0 -1 WITHSCORES", status);
assert(reply != NULL);
RCMD(c, "ZRANGE %s 0 -1 WITHSCORES", status);
n = reply->elements-1;
for (i=0; i<n; i=i+2) {
fprintf(fp, "%s %c %s\n", reply->element[i]->str, \
CSV_SEPARATOR, \
reply->element[i+1]->str);
}
freeReplyObject(reply);
fclose(fp);
return(0);
}


int main(int argc, char **argv) {
redisReply *reply;
redisReply *reply=NULL;
int i, n;
char *status;

Expand All @@ -86,22 +84,20 @@ int main(int argc, char **argv) {
exit(1);
}

RCMD(c, "FLUSHDB");
RCMD(c, "SELECT 0");
RCMD(c, "FLUSHDB");

n = sizeof(LOG_FILES)/sizeof(LOG_FILES[0]);
for (i = 0; i < n; i++) {
read_log(LOG_FILES[i], c);
}

reply = redisCommand(c, "SCAN 0 COUNT 10");
assert(reply != NULL);
RCMD(c, "SCAN 0 COUNT 10");
n = reply->element[1]->elements;
for (i=0; i<n; i++) {
status = reply->element[1]->element[i]->str;
write_csv(status, c);
}
freeReplyObject(reply);

redisFree(c);
return(0);
Expand Down
10 changes: 4 additions & 6 deletions docs/source/code/create-topchart.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
#include <hiredis.h>

#define RCMD(context, ...) { \
freeReplyObject(reply); \
reply = redisCommand(context, __VA_ARGS__); \
assert(reply != NULL); \
freeReplyObject(reply); \
}

const int SIZEOFLINE = 1023;
Expand All @@ -22,7 +22,7 @@ const char* filename = "redis.txt";

int main(int argc, char **argv) {
redisContext *c;
redisReply *reply;
redisReply *reply=NULL;
FILE *fp;
char line[SIZEOFLINE+1];
char* word;
Expand All @@ -39,8 +39,8 @@ int main(int argc, char **argv) {
exit(1);
}

RCMD(c, "FLUSHDB");
RCMD(c, "SELECT 0");
RCMD(c, "FLUSHDB");

fp = fopen(filename, "r");
while (fgets(line, SIZEOFLINE, fp) != NULL) {
Expand All @@ -54,13 +54,11 @@ int main(int argc, char **argv) {
}
fclose(fp);

reply = redisCommand(c, "ZRANGE \"topchart\" -10 -1 WITHSCORES");
assert(reply != NULL);
RCMD(c, "ZRANGE \"topchart\" -10 -1 WITHSCORES");
n = reply->elements-1;
for (i=0; i<n; i=i+2) {
printf("%s %s\n", reply->element[i+1]->str, reply->element[i]->str);
}
freeReplyObject(reply);

redisFree(c);
return(0);
Expand Down
7 changes: 4 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,13 @@
# import sphinx_rtd_theme
# html_theme = 'alabaster'
# html_theme = 'default'
html_theme = "sphinx_rtd_theme"
#html_theme = "guzzle_sphinx_theme"
# html_theme = "sphinx_rtd_theme"
html_theme = "guzzle_sphinx_theme"
html_theme_path = ["_themes", ]
#html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
else:
html_theme = 'default'
# html_theme = 'default'
html_theme = "guzzle_sphinx_theme"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
Expand Down
6 changes: 3 additions & 3 deletions docs/source/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Create frequency graph from a log

**Task:** Read /var/log/dpkg.log and create a graph to visualize how often packages are installed, upgraded and removed.

**Solution:** The loop (93) calls function *read_log* which reads the log line by line (33) and splits the fields date and time in minutes (35,39) and status (40,42). Third field of the log *status* is status of the dpkg operation(install, upgrade, remove ...). Command *ZINCRBY* (43) increments by 1 the score of *date* in the key *status*. As a result the database contains keys(install, upgrade, remove ...) and associated lists of *dates* sorted by score. Next loop (100) calls the function *write_csv* with first 10 keys. As a result *status.csv* files are created in the current directory with the *(date;score)* pairs.
**Solution:** The loop (91) calls function *read_log* which reads the log line by line (33) and splits the fields date and time in minutes (35,39) and status (40,42). Third field of the log *status* is status of the dpkg operation(install, upgrade, remove ...). Command *ZINCRBY* (43) increments by 1 the score of *date* in the key *status*. As a result the database contains keys(install, upgrade, remove ...) and associated lists of *dates* sorted by score. Next loop (97) calls the function *write_csv* with first 10 keys. As a result *status.csv* files are created in the current directory with the *(date;score)* pairs.

`[create-graph-01.c] <https://github.com/vbotka/redis-c-examples/blob/master/docs/source/code/create-graph-01.c>`_

Expand All @@ -15,7 +15,7 @@ Create frequency graph from a log

.. literalinclude:: code/create-graph-01.c
:language: c
:emphasize-lines: 43, 59, 78, 89, 90, 97, 106
:emphasize-lines: 43, 59, 76, 87, 88, 95, 102
:linenos:

**Result:** The *status.csv* files can be used to create a graph with *gnuplot*.
Expand All @@ -41,7 +41,7 @@ Command *ZINCRBY* (50) increments by 1 the score of *word* in the key *topchart*

.. literalinclude:: code/create-topchart.c
:language: c
:emphasize-lines: 31, 42, 43, 50, 57, 65
:emphasize-lines: 31, 42, 43, 50, 57, 63
:linenos:

**Result:**
Expand Down

0 comments on commit 25aad55

Please sign in to comment.