commit
cd74cf2a6b
625
tps/fonte/Game.c
625
tps/fonte/Game.c
|
|
@ -1,12 +1,15 @@
|
||||||
/**
|
/**
|
||||||
|
|
||||||
* @file Game.c
|
* @file Game.c
|
||||||
* @author Pedro Costa
|
* @author Pedro Lopes
|
||||||
* @version 0.1
|
* @version 0.2
|
||||||
* @date 2022-09-25
|
* @date 2022-10-02
|
||||||
*
|
|
||||||
* @copyright Copyright (c) 2022
|
* @copyright Copyright (c) 2022
|
||||||
*/
|
|
||||||
|
**/
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------------- //
|
||||||
|
|
||||||
// Includes
|
// Includes
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
@ -15,21 +18,23 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------------- //
|
||||||
|
|
||||||
// Definitions
|
// Definitions
|
||||||
#define MAX_GAMES 9000
|
#define MAX_GAMES 9000
|
||||||
#define MAX_FIELD_SIZE 250
|
#define MAX_FIELD_SIZE 250
|
||||||
#define MAX_STRING_ARRAY_SIZE 100
|
#define MAX_STRING_ARRAY_SIZE 100
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------------- //
|
||||||
|
|
||||||
// Structs
|
// Structs
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
int year,
|
int year,
|
||||||
month;
|
month;
|
||||||
} Date;
|
} Date;
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
char name[MAX_FIELD_SIZE],
|
char name[MAX_FIELD_SIZE],
|
||||||
owners[MAX_FIELD_SIZE],
|
owners[MAX_FIELD_SIZE],
|
||||||
website[MAX_FIELD_SIZE],
|
website[MAX_FIELD_SIZE],
|
||||||
|
|
@ -41,105 +46,75 @@ typedef struct
|
||||||
int app_id, age, dlcs, avg_playtime, count_languages, count_genres;
|
int app_id, age, dlcs, avg_playtime, count_languages, count_genres;
|
||||||
float price, upvotes;
|
float price, upvotes;
|
||||||
bool windows_os, mac_os, linux_os;
|
bool windows_os, mac_os, linux_os;
|
||||||
|
|
||||||
} Game;
|
} Game;
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------------- //
|
||||||
|
|
||||||
// Functions
|
// Global variables
|
||||||
bool isFim(char *str) { return str[0] == 'F' && str[1] == 'I' && str[2] == 'M'; }
|
Game games[MAX_GAMES];
|
||||||
|
int n = 0;
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------------- //
|
||||||
|
|
||||||
|
// Functions
|
||||||
|
bool isFim(char* line) { return line[0] == 'F' && line[1] == 'I' && line[2] == 'M'; }
|
||||||
|
|
||||||
|
void substring(char *string, char *string_start, int length) {
|
||||||
|
|
||||||
void substring(char *string, char *string_start, int length)
|
|
||||||
{
|
|
||||||
strncpy(string, string_start, length);
|
strncpy(string, string_start, length);
|
||||||
string[length] = '\0';
|
string[length] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
char *getMonthName(int month)
|
char *getMonthName(int month) {
|
||||||
{
|
|
||||||
switch (month)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
return "Jan";
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
return "Feb";
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
return "Mar";
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
return "Apr";
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
return "May";
|
|
||||||
break;
|
|
||||||
case 6:
|
|
||||||
return "Jun";
|
|
||||||
break;
|
|
||||||
case 7:
|
|
||||||
return "Jul";
|
|
||||||
break;
|
|
||||||
case 8:
|
|
||||||
return "Aug";
|
|
||||||
break;
|
|
||||||
case 9:
|
|
||||||
return "Sep";
|
|
||||||
break;
|
|
||||||
case 10:
|
|
||||||
return "Oct";
|
|
||||||
break;
|
|
||||||
case 11:
|
|
||||||
return "Nov";
|
|
||||||
break;
|
|
||||||
case 12:
|
|
||||||
return "Dec";
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
switch(month) {
|
||||||
return "N/A";
|
|
||||||
break;
|
case 1: return "Jan"; break;
|
||||||
|
case 2: return "Feb"; break;
|
||||||
|
case 3: return "Mar"; break;
|
||||||
|
case 4: return "Apr"; break;
|
||||||
|
case 5: return "May"; break;
|
||||||
|
case 6: return "Jun"; break;
|
||||||
|
case 7: return "Jul"; break;
|
||||||
|
case 8: return "Aug"; break;
|
||||||
|
case 9: return "Sep"; break;
|
||||||
|
case 10: return "Oct"; break;
|
||||||
|
case 11: return "Nov"; break;
|
||||||
|
case 12: return "Dec"; break;
|
||||||
|
|
||||||
|
default: return "N/A"; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int getMonthNumber(char *month)
|
int getMonthNumber(char* month) {
|
||||||
{
|
|
||||||
if (!strcmp(month, "Jan"))
|
if(!strcmp(month, "Jan")) return 1;
|
||||||
return 1;
|
else if(!strcmp(month, "Feb")) return 2;
|
||||||
else if (!strcmp(month, "Feb"))
|
else if(!strcmp(month, "Mar")) return 3;
|
||||||
return 2;
|
else if(!strcmp(month, "Apr")) return 4;
|
||||||
else if (!strcmp(month, "Mar"))
|
else if(!strcmp(month, "May")) return 5;
|
||||||
return 3;
|
else if(!strcmp(month, "Jun")) return 6;
|
||||||
else if (!strcmp(month, "Apr"))
|
else if(!strcmp(month, "Jul")) return 7;
|
||||||
return 4;
|
else if(!strcmp(month, "Aug")) return 8;
|
||||||
else if (!strcmp(month, "May"))
|
else if(!strcmp(month, "Sep")) return 9;
|
||||||
return 5;
|
else if(!strcmp(month, "Oct")) return 10;
|
||||||
else if (!strcmp(month, "Jun"))
|
else if(!strcmp(month, "Nov")) return 11;
|
||||||
return 6;
|
else if(!strcmp(month, "Dec")) return 12;
|
||||||
else if (!strcmp(month, "Jul"))
|
|
||||||
return 7;
|
|
||||||
else if (!strcmp(month, "Aug"))
|
|
||||||
return 8;
|
|
||||||
else if (!strcmp(month, "Sep"))
|
|
||||||
return 9;
|
|
||||||
else if (!strcmp(month, "Oct"))
|
|
||||||
return 10;
|
|
||||||
else if (!strcmp(month, "Nov"))
|
|
||||||
return 11;
|
|
||||||
else if (!strcmp(month, "Dec"))
|
|
||||||
return 12;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------------- //
|
||||||
|
|
||||||
// Class game functions
|
// Class game functions
|
||||||
void game_start(Game *game)
|
void game_start(Game *game) {
|
||||||
{
|
|
||||||
strcpy(game -> name, "");
|
strcpy(game -> name, "");
|
||||||
strcpy(game -> owners, "");
|
strcpy(game -> owners, "");
|
||||||
strcpy(game -> website, "");
|
strcpy(game -> website, "");
|
||||||
strcpy(game -> developers, "");
|
strcpy(game -> developers, "");
|
||||||
|
|
||||||
for (int i = 0; i < MAX_STRING_ARRAY_SIZE; i++)
|
for(int i = 0; i < MAX_STRING_ARRAY_SIZE; i++) {
|
||||||
{
|
|
||||||
strcpy(game -> languages[i], "");
|
strcpy(game -> languages[i], "");
|
||||||
strcpy(game -> genres[i], "");
|
strcpy(game -> genres[i], "");
|
||||||
}
|
}
|
||||||
|
|
@ -155,49 +130,43 @@ void game_start(Game *game)
|
||||||
game -> windows_os = false;
|
game -> windows_os = false;
|
||||||
game -> mac_os = false;
|
game -> mac_os = false;
|
||||||
game -> linux_os = false;
|
game -> linux_os = false;
|
||||||
|
|
||||||
game -> count_languages = 0;
|
game -> count_languages = 0;
|
||||||
game -> count_genres = 0;
|
game -> count_genres = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void game_print(Game *game)
|
void game_print(Game *game) {
|
||||||
{
|
|
||||||
int hours = game -> avg_playtime / 60,
|
int hours = game -> avg_playtime / 60,
|
||||||
minutes = game -> avg_playtime % 60;
|
minutes = game -> avg_playtime % 60;
|
||||||
|
|
||||||
printf("%i %s %s/%04i %s %i %.2f %i [", game -> app_id, game -> name, getMonthName(game -> release_date.month), game -> release_date.year, game -> owners, game -> age, game -> price, game -> dlcs);
|
printf("%i %s %s/%04i %s %i %.2f %i [", game -> app_id, game -> name, getMonthName(game -> release_date.month), game -> release_date.year, game -> owners, game -> age, game -> price, game -> dlcs);
|
||||||
|
|
||||||
for (int i = 0; i < game->count_languages; i++)
|
for(int i = 0; i < game -> count_languages; i++) {
|
||||||
{
|
|
||||||
printf("%s%s", game -> languages[i], i < game -> count_languages - 1 ? ", " : "");
|
printf("%s%s", game -> languages[i], i < game -> count_languages - 1 ? ", " : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("] %s %s %s %s ", game -> website, game -> windows_os ? "true" : "false", game -> mac_os ? "true" : "false", game -> linux_os ? "true" : "false");
|
printf("] %s %s %s %s ", game -> website, game -> windows_os ? "true" : "false", game -> mac_os ? "true" : "false", game -> linux_os ? "true" : "false");
|
||||||
|
|
||||||
if (isnan(game->upvotes))
|
if(isnan(game -> upvotes)) printf("0.0%% ");
|
||||||
printf("0.0%% ");
|
else printf("%.0f%% ", game -> upvotes);
|
||||||
else
|
|
||||||
printf("%.0f%% ", game->upvotes);
|
|
||||||
|
|
||||||
if(hours > 0)
|
if(hours > 0)
|
||||||
{
|
{
|
||||||
printf("%ih ", hours);
|
printf("%ih ", hours);
|
||||||
|
|
||||||
if (minutes > 0)
|
if(minutes > 0) printf("%im ", minutes);
|
||||||
printf("%im ", minutes);
|
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
|
|
||||||
if (minutes > 0)
|
if(minutes > 0) printf("%im ", minutes);
|
||||||
printf("%im ", minutes);
|
else printf("null ");
|
||||||
else
|
|
||||||
printf("null ");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("%s [", game -> developers);
|
printf("%s [", game -> developers);
|
||||||
|
|
||||||
for (int i = 0; i < game->count_genres; i++)
|
for(int i = 0; i < game -> count_genres; i++) {
|
||||||
{
|
|
||||||
|
|
||||||
printf("%s%s", game -> genres[i], i < game -> count_genres - 1 ? ", " : "");
|
printf("%s%s", game -> genres[i], i < game -> count_genres - 1 ? ", " : "");
|
||||||
}
|
}
|
||||||
|
|
@ -205,8 +174,7 @@ void game_print(Game *game)
|
||||||
printf("]\n");
|
printf("]\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
Game game_clone(Game *game)
|
Game game_clone(Game *game) {
|
||||||
{
|
|
||||||
|
|
||||||
Game cloned;
|
Game cloned;
|
||||||
|
|
||||||
|
|
@ -215,10 +183,8 @@ Game game_clone(Game *game)
|
||||||
strcpy(cloned.website, game -> website);
|
strcpy(cloned.website, game -> website);
|
||||||
strcpy(cloned.developers, game -> developers);
|
strcpy(cloned.developers, game -> developers);
|
||||||
|
|
||||||
for (int i = 0; i < game->count_languages; i++)
|
for(int i = 0; i < game -> count_languages; i++) strcpy(cloned.languages[i], game -> languages[i]);
|
||||||
strcpy(cloned.languages[i], game->languages[i]);
|
for(int i = 0; i < game -> count_genres; i++) strcpy(cloned.genres[i], game -> genres[i]);
|
||||||
for (int i = 0; i < game->count_genres; i++)
|
|
||||||
strcpy(cloned.genres[i], game->genres[i]);
|
|
||||||
|
|
||||||
cloned.release_date.month = game -> release_date.month;
|
cloned.release_date.month = game -> release_date.month;
|
||||||
cloned.release_date.year = game -> release_date.year;
|
cloned.release_date.year = game -> release_date.year;
|
||||||
|
|
@ -234,192 +200,232 @@ Game game_clone(Game *game)
|
||||||
return cloned;
|
return cloned;
|
||||||
}
|
}
|
||||||
|
|
||||||
void game_read(Game *game, char *line)
|
void game_read(Game *game, char *line) {
|
||||||
{
|
|
||||||
char c_search, sub[MAX_FIELD_SIZE];
|
char c_search, sub[MAX_FIELD_SIZE];
|
||||||
int index = 0, atr_index = 0;
|
int index = 0, atr_index = 0;
|
||||||
|
|
||||||
// ------------------------------------------------------------ //
|
// ------------------------------------------------------------ //
|
||||||
|
|
||||||
// Find "AppID"
|
// Find "AppID"
|
||||||
while (true)
|
while(true) {
|
||||||
{
|
|
||||||
index++;
|
index++;
|
||||||
if (line[index] == ',')
|
|
||||||
{
|
if(line[index] == ',') {
|
||||||
|
|
||||||
substring(sub, &line[atr_index], index - atr_index);
|
substring(sub, &line[atr_index], index - atr_index);
|
||||||
|
|
||||||
game -> app_id = atoi(sub);
|
game -> app_id = atoi(sub);
|
||||||
|
|
||||||
atr_index = ++index;
|
atr_index = ++index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------ //
|
// ------------------------------------------------------------ //
|
||||||
|
|
||||||
// Find "Name"
|
// Find "Name"
|
||||||
if (line[atr_index] != ',')
|
if(line[atr_index] != ',') {
|
||||||
{
|
|
||||||
if (line[atr_index] == '\"')
|
if(line[atr_index] == '\"') {
|
||||||
{
|
|
||||||
atr_index++;
|
atr_index++;
|
||||||
c_search = '\"';
|
c_search = '\"';
|
||||||
}
|
}
|
||||||
else
|
else c_search = ',';
|
||||||
c_search = ',';
|
|
||||||
while (true)
|
while(true) {
|
||||||
{
|
|
||||||
index++;
|
index++;
|
||||||
if (line[index] == c_search)
|
|
||||||
{
|
if(line[index] == c_search) {
|
||||||
|
|
||||||
substring(sub, &line[atr_index], index - atr_index);
|
substring(sub, &line[atr_index], index - atr_index);
|
||||||
strcpy(game -> name, sub);
|
strcpy(game -> name, sub);
|
||||||
if (c_search == ',')
|
|
||||||
index++;
|
if(c_search == ',') index++;
|
||||||
else if (c_search == '\"')
|
else if(c_search == '\"') index += 2;
|
||||||
index += 2;
|
|
||||||
atr_index = index;
|
atr_index = index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
strcpy(game -> name, "null");
|
strcpy(game -> name, "null");
|
||||||
|
|
||||||
atr_index = ++index;
|
atr_index = ++index;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------ //
|
// ------------------------------------------------------------ //
|
||||||
|
|
||||||
// Find release date
|
// Find release date
|
||||||
if (line[atr_index] != ',')
|
if(line[atr_index] != ',') {
|
||||||
{
|
|
||||||
if (line[atr_index] == '\"')
|
if(line[atr_index] == '\"') {
|
||||||
{
|
|
||||||
atr_index++;
|
atr_index++;
|
||||||
c_search = '\"';
|
c_search = '\"';
|
||||||
}
|
}
|
||||||
else
|
else c_search = ',';
|
||||||
c_search = ',';
|
|
||||||
while (true)
|
while(true) {
|
||||||
{
|
|
||||||
index++;
|
index++;
|
||||||
if (line[index] == c_search)
|
|
||||||
{
|
if(line[index] == c_search) {
|
||||||
|
|
||||||
substring(sub, &line[atr_index], index - atr_index);
|
substring(sub, &line[atr_index], index - atr_index);
|
||||||
|
|
||||||
char subDate[10];
|
char subDate[10];
|
||||||
|
|
||||||
substring(subDate, &sub[0], 3);
|
substring(subDate, &sub[0], 3);
|
||||||
|
|
||||||
game -> release_date.month = getMonthNumber(subDate);
|
game -> release_date.month = getMonthNumber(subDate);
|
||||||
if (c_search == ',')
|
|
||||||
{
|
if(c_search == ',') {
|
||||||
|
|
||||||
substring(subDate, &sub[4], 4);
|
substring(subDate, &sub[4], 4);
|
||||||
|
|
||||||
game -> release_date.year = atoi(subDate);
|
game -> release_date.year = atoi(subDate);
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
else if (c_search == '\"')
|
else if(c_search == '\"') {
|
||||||
{
|
|
||||||
int nmbSpace = 0;
|
int nmbSpace = 0;
|
||||||
for (int i = 0;; i++)
|
|
||||||
{
|
for(int i = 0; ; i++) {
|
||||||
if (sub[i] == ' ')
|
|
||||||
nmbSpace++;
|
if(sub[i] == ' ') nmbSpace++;
|
||||||
if (nmbSpace == 2)
|
|
||||||
{
|
if(nmbSpace == 2) {
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
substring(subDate, &sub[i], 4);
|
substring(subDate, &sub[i], 4);
|
||||||
|
|
||||||
game -> release_date.year = atoi(subDate);
|
game -> release_date.year = atoi(subDate);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
index += 2;
|
index += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
atr_index = index;
|
atr_index = index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
game -> release_date.month = 0;
|
game -> release_date.month = 0;
|
||||||
game -> release_date.year = 0;
|
game -> release_date.year = 0;
|
||||||
|
|
||||||
atr_index = ++index;
|
atr_index = ++index;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------ //
|
// ------------------------------------------------------------ //
|
||||||
|
|
||||||
// Find "Owners"
|
// Find "Owners"
|
||||||
while (true)
|
while(true) {
|
||||||
{
|
|
||||||
index++;
|
index++;
|
||||||
if (line[index] == ',')
|
|
||||||
{
|
if(line[index] == ',') {
|
||||||
|
|
||||||
substring(sub, &line[atr_index], index - atr_index);
|
substring(sub, &line[atr_index], index - atr_index);
|
||||||
strcpy(game -> owners, sub);
|
strcpy(game -> owners, sub);
|
||||||
|
|
||||||
atr_index = ++index;
|
atr_index = ++index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------ //
|
// ------------------------------------------------------------ //
|
||||||
|
|
||||||
// Find "Age"
|
// Find "Age"
|
||||||
while (true)
|
while(true) {
|
||||||
{
|
|
||||||
index++;
|
index++;
|
||||||
if (line[index] == ',')
|
|
||||||
{
|
if(line[index] == ',') {
|
||||||
|
|
||||||
substring(sub, &line[atr_index], index - atr_index);
|
substring(sub, &line[atr_index], index - atr_index);
|
||||||
|
|
||||||
game -> age = atoi(sub);
|
game -> age = atoi(sub);
|
||||||
|
|
||||||
atr_index = ++index;
|
atr_index = ++index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------ //
|
// ------------------------------------------------------------ //
|
||||||
|
|
||||||
// Find "Price"
|
// Find "Price"
|
||||||
while (true)
|
while(true) {
|
||||||
{
|
|
||||||
index++;
|
index++;
|
||||||
if (line[index] == ',')
|
|
||||||
{
|
if(line[index] == ',') {
|
||||||
|
|
||||||
substring(sub, &line[atr_index], index - atr_index);
|
substring(sub, &line[atr_index], index - atr_index);
|
||||||
|
|
||||||
game -> price = atof(sub);
|
game -> price = atof(sub);
|
||||||
|
|
||||||
atr_index = ++index;
|
atr_index = ++index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------ //
|
// ------------------------------------------------------------ //
|
||||||
|
|
||||||
// Find "DLCs"
|
// Find "DLCs"
|
||||||
while (true)
|
while(true) {
|
||||||
{
|
|
||||||
index++;
|
index++;
|
||||||
if (line[index] == ',')
|
|
||||||
{
|
if(line[index] == ',') {
|
||||||
|
|
||||||
substring(sub, &line[atr_index], index - atr_index);
|
substring(sub, &line[atr_index], index - atr_index);
|
||||||
|
|
||||||
game -> dlcs = atoi(sub);
|
game -> dlcs = atoi(sub);
|
||||||
|
|
||||||
atr_index = ++index;
|
atr_index = ++index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------ //
|
// ------------------------------------------------------------ //
|
||||||
|
|
||||||
// Find "Languages"
|
// Find "Languages"
|
||||||
while (true)
|
while(true) {
|
||||||
{
|
|
||||||
index++;
|
index++;
|
||||||
if (line[index] == ']')
|
|
||||||
{
|
if(line[index] == ']') {
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
if (line[index] == ',')
|
|
||||||
index++;
|
if(line[index] == ',') index++;
|
||||||
else if (line[index] == '\"')
|
else if(line[index] == '\"') index += 2;
|
||||||
index += 2;
|
|
||||||
atr_index = index;
|
atr_index = index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (line[index] == '\'')
|
else if(line[index] == '\'') {
|
||||||
{
|
|
||||||
int wordStart = index + 1;
|
int wordStart = index + 1;
|
||||||
while (true)
|
|
||||||
{
|
while(true) {
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
if (line[index] == '\'')
|
|
||||||
{
|
if(line[index] == '\'') {
|
||||||
|
|
||||||
substring(sub, &line[wordStart], index - wordStart);
|
substring(sub, &line[wordStart], index - wordStart);
|
||||||
strcpy(game -> languages[game -> count_languages++], sub);
|
strcpy(game -> languages[game -> count_languages++], sub);
|
||||||
break;
|
break;
|
||||||
|
|
@ -429,217 +435,294 @@ void game_read(Game *game, char *line)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------ //
|
// ------------------------------------------------------------ //
|
||||||
|
|
||||||
// Find "Website"
|
// Find "Website"
|
||||||
if (line[atr_index] != ',')
|
if(line[atr_index] != ',') {
|
||||||
{
|
|
||||||
if (line[atr_index] == '\"')
|
if(line[atr_index] == '\"') {
|
||||||
{
|
|
||||||
atr_index++;
|
atr_index++;
|
||||||
c_search = '\"';
|
c_search = '\"';
|
||||||
}
|
}
|
||||||
else
|
else c_search = ',';
|
||||||
c_search = ',';
|
|
||||||
while (true)
|
while(true) {
|
||||||
{
|
|
||||||
index++;
|
index++;
|
||||||
if (line[index] == c_search)
|
|
||||||
{
|
if(line[index] == c_search) {
|
||||||
|
|
||||||
substring(sub, &line[atr_index], index - atr_index);
|
substring(sub, &line[atr_index], index - atr_index);
|
||||||
strcpy(game -> website, sub);
|
strcpy(game -> website, sub);
|
||||||
|
|
||||||
atr_index = ++index;
|
atr_index = ++index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
strcpy(game -> website, "null");
|
strcpy(game -> website, "null");
|
||||||
|
|
||||||
atr_index = ++index;
|
atr_index = ++index;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------ //
|
// ------------------------------------------------------------ //
|
||||||
|
|
||||||
// Find "Windows"
|
// Find "Windows"
|
||||||
while (true)
|
while(true) {
|
||||||
{
|
|
||||||
index++;
|
index++;
|
||||||
if (line[index] == ',')
|
|
||||||
{
|
if(line[index] == ',') {
|
||||||
|
|
||||||
substring(sub, &line[atr_index], index - atr_index);
|
substring(sub, &line[atr_index], index - atr_index);
|
||||||
if (!strcmp(sub, "True"))
|
|
||||||
game->windows_os = true;
|
if(!strcmp(sub, "True")) game -> windows_os = true;
|
||||||
|
|
||||||
atr_index = ++index;
|
atr_index = ++index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find "Mac"
|
// Find "Mac"
|
||||||
while (true)
|
while(true) {
|
||||||
{
|
|
||||||
index++;
|
index++;
|
||||||
if (line[index] == ',')
|
|
||||||
{
|
if(line[index] == ',') {
|
||||||
|
|
||||||
substring(sub, &line[atr_index], index - atr_index);
|
substring(sub, &line[atr_index], index - atr_index);
|
||||||
if (!strcmp(sub, "True"))
|
|
||||||
game->mac_os = true;
|
if(!strcmp(sub, "True")) game -> mac_os = true;
|
||||||
|
|
||||||
atr_index = ++index;
|
atr_index = ++index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find "Linux"
|
// Find "Linux"
|
||||||
while (true)
|
while(true) {
|
||||||
{
|
|
||||||
index++;
|
index++;
|
||||||
if (line[index] == ',')
|
|
||||||
{
|
if(line[index] == ',') {
|
||||||
|
|
||||||
substring(sub, &line[atr_index], index - atr_index);
|
substring(sub, &line[atr_index], index - atr_index);
|
||||||
if (!strcmp(sub, "True"))
|
|
||||||
game->linux_os = true;
|
if(!strcmp(sub, "True")) game -> linux_os = true;
|
||||||
|
|
||||||
atr_index = ++index;
|
atr_index = ++index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------ //
|
// ------------------------------------------------------------ //
|
||||||
|
|
||||||
// Find "Upvotes"
|
// Find "Upvotes"
|
||||||
int positives, negatives;
|
int positives, negatives;
|
||||||
while (true)
|
|
||||||
{
|
while(true) {
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
if (line[index] == ',')
|
|
||||||
{
|
if(line[index] == ',') {
|
||||||
|
|
||||||
substring(sub, &line[atr_index], index - atr_index);
|
substring(sub, &line[atr_index], index - atr_index);
|
||||||
|
|
||||||
positives = atoi(sub);
|
positives = atoi(sub);
|
||||||
atr_index = ++index;
|
atr_index = ++index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (true)
|
|
||||||
{
|
while(true) {
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
if (line[index] == ',')
|
|
||||||
{
|
if(line[index] == ',') {
|
||||||
|
|
||||||
substring(sub, &line[atr_index], index - atr_index);
|
substring(sub, &line[atr_index], index - atr_index);
|
||||||
|
|
||||||
negatives = atoi(sub);
|
negatives = atoi(sub);
|
||||||
atr_index = ++index;
|
atr_index = ++index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
game -> upvotes = (float)(positives * 100) / (float)(positives + negatives);
|
game -> upvotes = (float)(positives * 100) / (float)(positives + negatives);
|
||||||
|
|
||||||
// ------------------------------------------------------------ //
|
// ------------------------------------------------------------ //
|
||||||
|
|
||||||
// Find "AVG Playtime"
|
// Find "AVG Playtime"
|
||||||
while (true)
|
while(true) {
|
||||||
{
|
|
||||||
index++;
|
index++;
|
||||||
if (line[index] == ',')
|
|
||||||
{
|
if(line[index] == ',') {
|
||||||
|
|
||||||
substring(sub, &line[atr_index], index - atr_index);
|
substring(sub, &line[atr_index], index - atr_index);
|
||||||
|
|
||||||
game -> avg_playtime = atoi(sub);
|
game -> avg_playtime = atoi(sub);
|
||||||
|
|
||||||
atr_index = ++index;
|
atr_index = ++index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------ //
|
// ------------------------------------------------------------ //
|
||||||
|
|
||||||
// Find "Developers"
|
// Find "Developers"
|
||||||
if (line[atr_index] != ',')
|
if(line[atr_index] != ',') {
|
||||||
{
|
|
||||||
if (line[atr_index] == '\"')
|
if(line[atr_index] == '\"') {
|
||||||
{
|
|
||||||
atr_index++;
|
atr_index++;
|
||||||
c_search = '\"';
|
c_search = '\"';
|
||||||
}
|
}
|
||||||
else
|
else c_search = ',';
|
||||||
c_search = ',';
|
|
||||||
|
while(true) {
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
index++;
|
index++;
|
||||||
if (line[index] == c_search)
|
|
||||||
{
|
if(line[index] == c_search) {
|
||||||
|
|
||||||
substring(sub, &line[atr_index], index - atr_index);
|
substring(sub, &line[atr_index], index - atr_index);
|
||||||
strcpy(game -> developers, sub);
|
strcpy(game -> developers, sub);
|
||||||
|
|
||||||
atr_index = ++index;
|
atr_index = ++index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
strcpy(game -> developers, "null");
|
strcpy(game -> developers, "null");
|
||||||
|
|
||||||
atr_index = ++index;
|
atr_index = ++index;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------ //
|
// ------------------------------------------------------------ //
|
||||||
|
|
||||||
// Find "Genres"
|
// Find "Genres"
|
||||||
if (index < strlen(line) - 1)
|
if(index < strlen(line) - 1) {
|
||||||
{
|
|
||||||
if (line[index] == ',')
|
if(line[index] == ',') atr_index = ++index;
|
||||||
atr_index = ++index;
|
|
||||||
if (line[atr_index] == '\"')
|
if(line[atr_index] == '\"') {
|
||||||
{
|
|
||||||
atr_index++;
|
atr_index++;
|
||||||
while (true)
|
|
||||||
{
|
while(true) {
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
if (line[index] == ',')
|
|
||||||
{
|
if(line[index] == ',') {
|
||||||
|
|
||||||
substring(sub, &line[atr_index], index - atr_index);
|
substring(sub, &line[atr_index], index - atr_index);
|
||||||
strcpy(game -> genres[game -> count_genres++], sub);
|
strcpy(game -> genres[game -> count_genres++], sub);
|
||||||
|
|
||||||
atr_index = ++index;
|
atr_index = ++index;
|
||||||
}
|
}
|
||||||
else if (line[index] == '\"')
|
else if(line[index] == '\"') {
|
||||||
{
|
|
||||||
substring(sub, &line[atr_index], strlen(line) - 1 - atr_index);
|
substring(sub, &line[atr_index], strlen(line) - 1 - atr_index);
|
||||||
if (sub[strlen(sub) - 2] == '\"')
|
|
||||||
sub[strlen(sub) - 2] = '\0';
|
if(sub[strlen(sub) - 1] == '\"') sub[strlen(sub) - 1] = '\0';
|
||||||
|
else if(sub[strlen(sub) - 2] == '\"') sub[strlen(sub) - 2] = '\0';
|
||||||
|
|
||||||
strcpy(game -> genres[game -> count_genres++], sub);
|
strcpy(game -> genres[game -> count_genres++], sub);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
substring(sub, &line[atr_index], strlen(line) - 1 - atr_index);
|
substring(sub, &line[atr_index], strlen(line) - 2 - atr_index);
|
||||||
sub[strlen(line) - 2 - atr_index] = '\0';
|
|
||||||
strcpy(game -> genres[game -> count_genres++], sub);
|
strcpy(game -> genres[game -> count_genres++], sub);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------------- //
|
||||||
|
|
||||||
|
// Functions - List
|
||||||
|
void list_insert(Game x) {
|
||||||
|
|
||||||
|
if(n >= MAX_GAMES) {
|
||||||
|
|
||||||
|
printf("Insert error: MAX_GAMES reached");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
games[n++] = x;
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------------------------------- //
|
// ---------------------------------------------------------------------------------------------------------- //
|
||||||
|
|
||||||
int main()
|
int main() {
|
||||||
{
|
|
||||||
char csvFile[20];
|
|
||||||
scanf("%s", csvFile);
|
|
||||||
|
|
||||||
|
// ------------------------------------------------------------ //
|
||||||
|
|
||||||
|
// First part - Read all games
|
||||||
|
|
||||||
|
// Open CSV file
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char *line = NULL;
|
char *line = NULL;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
ssize_t read;
|
size_t read;
|
||||||
|
|
||||||
fp = fopen(csvFile, "r");
|
fp = fopen("/tmp/games.csv", "r");
|
||||||
|
|
||||||
if (fp == NULL)
|
if(fp == NULL) exit(EXIT_FAILURE);
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
|
|
||||||
// ------------------------------------------------------------ //
|
// ------------------------- //
|
||||||
|
|
||||||
|
// Fill games list
|
||||||
|
while((read = getline(&line, &len, fp)) != -1) {
|
||||||
|
|
||||||
while ((read = getline(&line, &len, fp)) != -1)
|
|
||||||
{
|
|
||||||
Game game;
|
Game game;
|
||||||
|
|
||||||
game_start(&game);
|
game_start(&game);
|
||||||
game_read(&game, line);
|
game_read(&game, line);
|
||||||
game_print(&game);
|
list_insert(game);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------ //
|
// ------------------------- //
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
if (line)
|
if(line) free(line);
|
||||||
free(line);
|
|
||||||
|
|
||||||
|
// ------------------------------------------------------------ //
|
||||||
|
|
||||||
|
// Second part - Print .in games
|
||||||
|
|
||||||
|
char in[15];
|
||||||
|
scanf(" %[^\n]s", in);
|
||||||
|
|
||||||
|
while(true) {
|
||||||
|
|
||||||
|
if(isFim(in)) break;
|
||||||
|
else {
|
||||||
|
|
||||||
|
int app_id = atoi(in);
|
||||||
|
|
||||||
|
for(int i = 0; i < n; i++) {
|
||||||
|
|
||||||
|
if(games[i].app_id == app_id) {
|
||||||
|
|
||||||
|
game_print(&games[i]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------- //
|
||||||
|
|
||||||
|
scanf(" %[^\n]s", in);
|
||||||
|
}
|
||||||
|
}
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
@ -1,19 +1,29 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
||||||
* @file Game.java
|
* @file Game.java
|
||||||
* @author Pedro Costa
|
* @author Pedro Lopes
|
||||||
* @version 0.1
|
* @version 0.2
|
||||||
* @date 2022-09-25
|
* @date 2022-10-02
|
||||||
*
|
|
||||||
* @copyright Copyright (c) 2022
|
* @copyright Copyright (c) 2022
|
||||||
*/
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------------------------------------------- //
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class Game {
|
// ----------------------------------------------------------------------------------------------------------------- //
|
||||||
|
|
||||||
|
class Game {
|
||||||
|
|
||||||
static SimpleDateFormat default_dateFormat = new SimpleDateFormat("MMM/yyyy", Locale.ENGLISH);
|
static SimpleDateFormat default_dateFormat = new SimpleDateFormat("MMM/yyyy", Locale.ENGLISH);
|
||||||
|
|
||||||
|
|
@ -25,6 +35,7 @@ public class Game {
|
||||||
private boolean windows, mac, linux;
|
private boolean windows, mac, linux;
|
||||||
|
|
||||||
public Game() {
|
public Game() {
|
||||||
|
|
||||||
this.name = this.owners = this.website = this.developers = null;
|
this.name = this.owners = this.website = this.developers = null;
|
||||||
this.languages = new ArrayList<String>();
|
this.languages = new ArrayList<String>();
|
||||||
this.genres = new ArrayList<String>();
|
this.genres = new ArrayList<String>();
|
||||||
|
|
@ -34,9 +45,8 @@ public class Game {
|
||||||
this.windows = this.mac = this.linux = false;
|
this.windows = this.mac = this.linux = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Game(String name, String owners, String website, String developers, ArrayList<String> languages,
|
public Game(String name, String owners, String website, String developers, ArrayList<String> languages, ArrayList<String> genres, Date release_date, int app_id, int age, int dlcs, int upvotes, int avg_playtime, float price, boolean windows, boolean mac, boolean linux) {
|
||||||
ArrayList<String> genres, Date release_date, int app_id, int age, int dlcs, int upvotes, int avg_playtime,
|
|
||||||
float price, boolean windows, boolean mac, boolean linux) {
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.owners = owners;
|
this.owners = owners;
|
||||||
this.website = website;
|
this.website = website;
|
||||||
|
|
@ -55,136 +65,44 @@ public class Game {
|
||||||
this.linux = linux;
|
this.linux = linux;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
public void setName(String name) { this.name = name; }
|
||||||
this.name = name;
|
public void setOwners(String owners) { this.owners = owners; }
|
||||||
}
|
public void setWebsite(String website) { this.website = website; }
|
||||||
|
public void setDevelopers(String developers) { this.developers = developers; }
|
||||||
|
public void setLanguages(ArrayList<String> languages) { this.languages = languages; }
|
||||||
|
public void setGenres(ArrayList<String> genres) { this.genres = genres; }
|
||||||
|
public void setReleaseDate(Date release_date) { this.release_date = release_date; }
|
||||||
|
public void setAppId(int app_id) { this.app_id = app_id; }
|
||||||
|
public void setAge(int age) { this.age = age; }
|
||||||
|
public void setDlcs(int dlcs) { this.dlcs = dlcs; }
|
||||||
|
public void setAvgPlaytime(int avg_playtime) { this.avg_playtime = avg_playtime; }
|
||||||
|
public void setPrice(float price) { this.price = price; }
|
||||||
|
public void setUpvotes(float upvotes) { this.upvotes = upvotes; }
|
||||||
|
public void setWindows(boolean windows) { this.windows = windows; }
|
||||||
|
public void setMac(boolean mac) { this.mac = mac; }
|
||||||
|
public void setLinux(boolean linux) { this.linux = linux; }
|
||||||
|
|
||||||
public void setOwners(String owners) {
|
public String getName() { return this.name; }
|
||||||
this.owners = owners;
|
public String getOwners() { return this.owners; }
|
||||||
}
|
public String getWebsite() { return this.website; }
|
||||||
|
public String getDevelopers() { return this.developers; }
|
||||||
public void setWebsite(String website) {
|
public ArrayList<String> getLanguages() { return this.languages; }
|
||||||
this.website = website;
|
public ArrayList<String> getGenres() { return this.genres; }
|
||||||
}
|
public Date getReleaseDate() { return this.release_date; }
|
||||||
|
public int getAppId() { return this.app_id; }
|
||||||
public void setDevelopers(String developers) {
|
public int getAge() { return this.age; }
|
||||||
this.developers = developers;
|
public int getDlcs() { return this.dlcs; }
|
||||||
}
|
public int getAvgPlaytime() { return this.avg_playtime; }
|
||||||
|
public float getPrice() { return this.price; }
|
||||||
public void setLanguages(ArrayList<String> languages) {
|
public float getUpvotes() { return this.upvotes; }
|
||||||
this.languages = languages;
|
public boolean getWindows() { return this.windows; }
|
||||||
}
|
public boolean getMac() { return this.mac; }
|
||||||
|
public boolean getLinux() { return this.linux; }
|
||||||
public void setGenres(ArrayList<String> genres) {
|
|
||||||
this.genres = genres;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setReleaseDate(Date release_date) {
|
|
||||||
this.release_date = release_date;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAppId(int app_id) {
|
|
||||||
this.app_id = app_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAge(int age) {
|
|
||||||
this.age = age;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDlcs(int dlcs) {
|
|
||||||
this.dlcs = dlcs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAvgPlaytime(int avg_playtime) {
|
|
||||||
this.avg_playtime = avg_playtime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPrice(float price) {
|
|
||||||
this.price = price;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUpvotes(float upvotes) {
|
|
||||||
this.upvotes = upvotes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setWindows(boolean windows) {
|
|
||||||
this.windows = windows;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMac(boolean mac) {
|
|
||||||
this.mac = mac;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLinux(boolean linux) {
|
|
||||||
this.linux = linux;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return this.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getOwners() {
|
|
||||||
return this.owners;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getWebsite() {
|
|
||||||
return this.website;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDevelopers() {
|
|
||||||
return this.developers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<String> getLanguages() {
|
|
||||||
return this.languages;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<String> getGenres() {
|
|
||||||
return this.genres;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getReleaseDate() {
|
|
||||||
return this.release_date;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getAppId() {
|
|
||||||
return this.app_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getAge() {
|
|
||||||
return this.age;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getDlcs() {
|
|
||||||
return this.dlcs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getAvgPlaytime() {
|
|
||||||
return this.avg_playtime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getPrice() {
|
|
||||||
return this.price;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getUpvotes() {
|
|
||||||
return this.upvotes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getWindows() {
|
|
||||||
return this.windows;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getMac() {
|
|
||||||
return this.mac;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getLinux() {
|
|
||||||
return this.linux;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Game clone() {
|
public Game clone() {
|
||||||
|
|
||||||
Game cloned = new Game();
|
Game cloned = new Game();
|
||||||
|
|
||||||
cloned.name = this.name;
|
cloned.name = this.name;
|
||||||
cloned.owners = this.owners;
|
cloned.owners = this.owners;
|
||||||
cloned.website = this.website;
|
cloned.website = this.website;
|
||||||
|
|
@ -201,139 +119,192 @@ public class Game {
|
||||||
cloned.windows = this.windows;
|
cloned.windows = this.windows;
|
||||||
cloned.mac = this.mac;
|
cloned.mac = this.mac;
|
||||||
cloned.linux = this.linux;
|
cloned.linux = this.linux;
|
||||||
|
|
||||||
return cloned;
|
return cloned;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ler(String line) {
|
public void read(String line) {
|
||||||
|
|
||||||
char c_search;
|
char c_search;
|
||||||
int index = 0, atr_index = 0;
|
int index = 0, atr_index = 0;
|
||||||
|
|
||||||
// ---------------------------------- //
|
// ---------------------------------- //
|
||||||
|
|
||||||
// Find "AppID"
|
// Find "AppID"
|
||||||
while(true) {
|
while(true) {
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
|
|
||||||
if(line.charAt(index) == ',') {
|
if(line.charAt(index) == ',') {
|
||||||
|
|
||||||
this.app_id = Integer.parseInt(line.substring(atr_index, index));
|
this.app_id = Integer.parseInt(line.substring(atr_index, index));
|
||||||
|
|
||||||
atr_index = ++index;
|
atr_index = ++index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------- //
|
// ---------------------------------- //
|
||||||
|
|
||||||
// Find "Name"
|
// Find "Name"
|
||||||
if(line.charAt(atr_index) != ',') {
|
if(line.charAt(atr_index) != ',') {
|
||||||
|
|
||||||
if(line.charAt(atr_index) == '\"') {
|
if(line.charAt(atr_index) == '\"') {
|
||||||
|
|
||||||
atr_index++;
|
atr_index++;
|
||||||
c_search = '\"';
|
c_search = '\"';
|
||||||
} else
|
}
|
||||||
c_search = ',';
|
else c_search = ',';
|
||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
|
|
||||||
if(line.charAt(index) == c_search) {
|
if(line.charAt(index) == c_search) {
|
||||||
|
|
||||||
this.name = line.substring(atr_index, index);
|
this.name = line.substring(atr_index, index);
|
||||||
if (c_search == ',')
|
|
||||||
index++;
|
if(c_search == ',') index++;
|
||||||
else if (c_search == '\"')
|
else if(c_search == '\"') index += 2;
|
||||||
index += 2;
|
|
||||||
atr_index = index;
|
atr_index = index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else
|
}
|
||||||
atr_index = ++index;
|
else atr_index = ++index;
|
||||||
|
|
||||||
// ---------------------------------- //
|
// ---------------------------------- //
|
||||||
|
|
||||||
// Find release date
|
// Find release date
|
||||||
if(line.charAt(atr_index) != ',') {
|
if(line.charAt(atr_index) != ',') {
|
||||||
|
|
||||||
SimpleDateFormat df;
|
SimpleDateFormat df;
|
||||||
|
|
||||||
if(line.charAt(atr_index) == '\"') {
|
if(line.charAt(atr_index) == '\"') {
|
||||||
|
|
||||||
df = new SimpleDateFormat("MMM dd, yyyy", Locale.ENGLISH);
|
df = new SimpleDateFormat("MMM dd, yyyy", Locale.ENGLISH);
|
||||||
|
|
||||||
atr_index++;
|
atr_index++;
|
||||||
c_search = '\"';
|
c_search = '\"';
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
df = new SimpleDateFormat("MMM yyyy", Locale.ENGLISH);
|
df = new SimpleDateFormat("MMM yyyy", Locale.ENGLISH);
|
||||||
|
|
||||||
c_search = ',';
|
c_search = ',';
|
||||||
}
|
}
|
||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
|
|
||||||
if(line.charAt(index) == c_search) {
|
if(line.charAt(index) == c_search) {
|
||||||
try {
|
|
||||||
this.release_date = df.parse(line.substring(atr_index, index));
|
try { this.release_date = df.parse(line.substring(atr_index, index)); }
|
||||||
} catch (java.text.ParseException e) {
|
catch (java.text.ParseException e) { e.printStackTrace(); }
|
||||||
e.printStackTrace();
|
|
||||||
}
|
if(c_search == ',') index++;
|
||||||
if (c_search == ',')
|
else if(c_search == '\"') index += 2;
|
||||||
index++;
|
|
||||||
else if (c_search == '\"')
|
|
||||||
index += 2;
|
|
||||||
atr_index = index;
|
atr_index = index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else
|
}
|
||||||
atr_index = ++index;
|
else atr_index = ++index;
|
||||||
|
|
||||||
// ---------------------------------- //
|
// ---------------------------------- //
|
||||||
|
|
||||||
// Find "Owners"
|
// Find "Owners"
|
||||||
while(true) {
|
while(true) {
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
|
|
||||||
if(line.charAt(index) == ',') {
|
if(line.charAt(index) == ',') {
|
||||||
|
|
||||||
this.owners = line.substring(atr_index, index);
|
this.owners = line.substring(atr_index, index);
|
||||||
|
|
||||||
atr_index = ++index;
|
atr_index = ++index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------- //
|
// ---------------------------------- //
|
||||||
|
|
||||||
// Find "Age"
|
// Find "Age"
|
||||||
while(true) {
|
while(true) {
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
|
|
||||||
if(line.charAt(index) == ',') {
|
if(line.charAt(index) == ',') {
|
||||||
|
|
||||||
this.age = Integer.parseInt(line.substring(atr_index, index));
|
this.age = Integer.parseInt(line.substring(atr_index, index));
|
||||||
|
|
||||||
atr_index = ++index;
|
atr_index = ++index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------- //
|
// ---------------------------------- //
|
||||||
|
|
||||||
// Find "Price"
|
// Find "Price"
|
||||||
while(true) {
|
while(true) {
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
|
|
||||||
if(line.charAt(index) == ',') {
|
if(line.charAt(index) == ',') {
|
||||||
|
|
||||||
this.price = Float.parseFloat(line.substring(atr_index, index));
|
this.price = Float.parseFloat(line.substring(atr_index, index));
|
||||||
|
|
||||||
atr_index = ++index;
|
atr_index = ++index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------- //
|
// ---------------------------------- //
|
||||||
|
|
||||||
// Find "DLCs"
|
// Find "DLCs"
|
||||||
while(true) {
|
while(true) {
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
|
|
||||||
if(line.charAt(index) == ',') {
|
if(line.charAt(index) == ',') {
|
||||||
|
|
||||||
this.dlcs = Integer.parseInt(line.substring(atr_index, index));
|
this.dlcs = Integer.parseInt(line.substring(atr_index, index));
|
||||||
|
|
||||||
atr_index = ++index;
|
atr_index = ++index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------- //
|
// ---------------------------------- //
|
||||||
|
|
||||||
// Find "Languages"
|
// Find "Languages"
|
||||||
while(true) {
|
while(true) {
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
|
|
||||||
if(line.charAt(index) == ']') {
|
if(line.charAt(index) == ']') {
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
if (line.charAt(index) == ',')
|
|
||||||
index++;
|
if(line.charAt(index) == ',') index++;
|
||||||
else if (line.charAt(index) == '\"')
|
else if(line.charAt(index) == '\"') index += 2;
|
||||||
index += 2;
|
|
||||||
atr_index = index;
|
atr_index = index;
|
||||||
break;
|
break;
|
||||||
} else if (line.charAt(index) == '\'') {
|
}
|
||||||
|
else if(line.charAt(index) == '\'') {
|
||||||
|
|
||||||
int wordStart = index + 1;
|
int wordStart = index + 1;
|
||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
|
|
||||||
if(line.charAt(index) == '\'') {
|
if(line.charAt(index) == '\'') {
|
||||||
|
|
||||||
this.languages.add(line.substring(wordStart, index));
|
this.languages.add(line.substring(wordStart, index));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -342,32 +313,43 @@ public class Game {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------- //
|
// ---------------------------------- //
|
||||||
|
|
||||||
// Find "Website"
|
// Find "Website"
|
||||||
if(line.charAt(atr_index) != ',') {
|
if(line.charAt(atr_index) != ',') {
|
||||||
|
|
||||||
if(line.charAt(atr_index) == '\"') {
|
if(line.charAt(atr_index) == '\"') {
|
||||||
|
|
||||||
atr_index++;
|
atr_index++;
|
||||||
c_search = '\"';
|
c_search = '\"';
|
||||||
} else
|
}
|
||||||
c_search = ',';
|
else c_search = ',';
|
||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
|
|
||||||
if(line.charAt(index) == c_search) {
|
if(line.charAt(index) == c_search) {
|
||||||
|
|
||||||
this.website = line.substring(atr_index, index);
|
this.website = line.substring(atr_index, index);
|
||||||
|
|
||||||
atr_index = ++index;
|
atr_index = ++index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else
|
}
|
||||||
atr_index = ++index;
|
else atr_index = ++index;
|
||||||
|
|
||||||
// ---------------------------------- //
|
// ---------------------------------- //
|
||||||
|
|
||||||
// Find "Windows"
|
// Find "Windows"
|
||||||
while(true) {
|
while(true) {
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
|
|
||||||
if(line.charAt(index) == ',') {
|
if(line.charAt(index) == ',') {
|
||||||
|
|
||||||
this.windows = Boolean.parseBoolean(line.substring(atr_index, index));
|
this.windows = Boolean.parseBoolean(line.substring(atr_index, index));
|
||||||
|
|
||||||
atr_index = ++index;
|
atr_index = ++index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -375,9 +357,13 @@ public class Game {
|
||||||
|
|
||||||
// Find "Mac"
|
// Find "Mac"
|
||||||
while(true) {
|
while(true) {
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
|
|
||||||
if(line.charAt(index) == ',') {
|
if(line.charAt(index) == ',') {
|
||||||
|
|
||||||
this.mac = Boolean.parseBoolean(line.substring(atr_index, index));
|
this.mac = Boolean.parseBoolean(line.substring(atr_index, index));
|
||||||
|
|
||||||
atr_index = ++index;
|
atr_index = ++index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -385,106 +371,207 @@ public class Game {
|
||||||
|
|
||||||
// Find "Linux"
|
// Find "Linux"
|
||||||
while(true) {
|
while(true) {
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
|
|
||||||
if(line.charAt(index) == ',') {
|
if(line.charAt(index) == ',') {
|
||||||
|
|
||||||
this.linux = Boolean.parseBoolean(line.substring(atr_index, index));
|
this.linux = Boolean.parseBoolean(line.substring(atr_index, index));
|
||||||
|
|
||||||
atr_index = ++index;
|
atr_index = ++index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------- //
|
// ---------------------------------- //
|
||||||
|
|
||||||
// Find "Upvotes"
|
// Find "Upvotes"
|
||||||
int positives, negatives;
|
int positives, negatives;
|
||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
|
|
||||||
if(line.charAt(index) == ',') {
|
if(line.charAt(index) == ',') {
|
||||||
|
|
||||||
positives = Integer.parseInt(line.substring(atr_index, index));
|
positives = Integer.parseInt(line.substring(atr_index, index));
|
||||||
|
|
||||||
atr_index = ++index;
|
atr_index = ++index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
|
|
||||||
if(line.charAt(index) == ',') {
|
if(line.charAt(index) == ',') {
|
||||||
|
|
||||||
negatives = Integer.parseInt(line.substring(atr_index, index));
|
negatives = Integer.parseInt(line.substring(atr_index, index));
|
||||||
|
|
||||||
atr_index = ++index;
|
atr_index = ++index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.upvotes = (float)(positives * 100) / (float)(positives + negatives);
|
this.upvotes = (float)(positives * 100) / (float)(positives + negatives);
|
||||||
|
|
||||||
// ---------------------------------- //
|
// ---------------------------------- //
|
||||||
|
|
||||||
// Find "AVG Playtime"
|
// Find "AVG Playtime"
|
||||||
while(true) {
|
while(true) {
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
|
|
||||||
if(line.charAt(index) == ',') {
|
if(line.charAt(index) == ',') {
|
||||||
|
|
||||||
this.avg_playtime = Integer.parseInt(line.substring(atr_index, index));
|
this.avg_playtime = Integer.parseInt(line.substring(atr_index, index));
|
||||||
|
|
||||||
atr_index = ++index;
|
atr_index = ++index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------- //
|
// ---------------------------------- //
|
||||||
|
|
||||||
// Find "Developers"
|
// Find "Developers"
|
||||||
if(line.charAt(atr_index) != ',') {
|
if(line.charAt(atr_index) != ',') {
|
||||||
|
|
||||||
if(line.charAt(atr_index) == '\"') {
|
if(line.charAt(atr_index) == '\"') {
|
||||||
|
|
||||||
atr_index++;
|
atr_index++;
|
||||||
c_search = '\"';
|
c_search = '\"';
|
||||||
} else
|
}
|
||||||
c_search = ',';
|
else c_search = ',';
|
||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
|
|
||||||
if(line.charAt(index) == c_search) {
|
if(line.charAt(index) == c_search) {
|
||||||
|
|
||||||
this.developers = line.substring(atr_index, index);
|
this.developers = line.substring(atr_index, index);
|
||||||
|
|
||||||
atr_index = ++index;
|
atr_index = ++index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else
|
}
|
||||||
atr_index = ++index;
|
else atr_index = ++index;
|
||||||
|
|
||||||
// ---------------------------------- //
|
// ---------------------------------- //
|
||||||
|
|
||||||
// Find "Genres"
|
// Find "Genres"
|
||||||
if(index < line.length() - 1) {
|
if(index < line.length() - 1) {
|
||||||
if (line.charAt(index) == ',')
|
|
||||||
atr_index = ++index;
|
if(line.charAt(index) == ',') atr_index = ++index;
|
||||||
if(line.charAt(atr_index) == '\"') {
|
if(line.charAt(atr_index) == '\"') {
|
||||||
|
|
||||||
atr_index++;
|
atr_index++;
|
||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
|
|
||||||
if(line.charAt(index) == ',') {
|
if(line.charAt(index) == ',') {
|
||||||
|
|
||||||
this.genres.add(line.substring(atr_index, index));
|
this.genres.add(line.substring(atr_index, index));
|
||||||
|
|
||||||
atr_index = ++index;
|
atr_index = ++index;
|
||||||
} else if (line.charAt(index) == '\"') {
|
}
|
||||||
|
else if(line.charAt(index) == '\"') {
|
||||||
|
|
||||||
this.genres.add(line.substring(atr_index, line.length() - 1));
|
this.genres.add(line.substring(atr_index, line.length() - 1));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else
|
|
||||||
this.genres.add(line.substring(atr_index, line.length()));
|
|
||||||
}
|
}
|
||||||
|
else this.genres.add(line.substring(atr_index, line.length()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void imprimir() {
|
// -------------------------------------------------------------------------------- //
|
||||||
|
}
|
||||||
|
|
||||||
|
public void print() {
|
||||||
|
|
||||||
String avg_pt = null;
|
String avg_pt = null;
|
||||||
if (this.avg_playtime == 0)
|
|
||||||
avg_pt = "null ";
|
if(this.avg_playtime == 0) avg_pt = "null ";
|
||||||
else if (this.avg_playtime < 60)
|
else if(this.avg_playtime < 60) avg_pt = this.avg_playtime + "m ";
|
||||||
avg_pt = this.avg_playtime + "m ";
|
|
||||||
else {
|
else {
|
||||||
if (this.avg_playtime % 60 == 0)
|
|
||||||
avg_pt = this.avg_playtime / 60 + "h ";
|
if(this.avg_playtime % 60 == 0) avg_pt = this.avg_playtime / 60 + "h ";
|
||||||
else
|
else avg_pt = (this.avg_playtime / 60) + "h " + (this.avg_playtime % 60) + "m ";
|
||||||
avg_pt = (this.avg_playtime / 60) + "h " + (this.avg_playtime % 60) + "m ";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DecimalFormat df = new DecimalFormat("##");
|
DecimalFormat df = new DecimalFormat("##");
|
||||||
System.out.println(this.app_id + " " + this.name + " " + default_dateFormat.format(this.release_date) + " "
|
|
||||||
+ this.owners + " " + this.age + " " + String.format("%.2f", this.price) + " " + this.dlcs + " "
|
System.out.println(this.app_id + " " + this.name + " " + default_dateFormat.format(this.release_date) + " " + this.owners + " " + this.age + " " + String.format(Locale.ENGLISH, "%.2f", this.price) + " " + this.dlcs + " " + this.languages + " " + this.website + " " + this.windows + " " + this.mac + " " + this.linux + " " + (Float.isNaN(this.upvotes) ? "0% " : df.format(this.upvotes) + "% ") + avg_pt + this.developers + " " + this.genres);
|
||||||
+ this.languages + " " + this.website + " " + this.windows + " " + this.mac + " " + this.linux + " "
|
|
||||||
+ (Float.isNaN(this.upvotes) ? "0.0% " : df.format(this.upvotes) + "% ") + avg_pt + this.developers
|
|
||||||
+ " " + this.genres);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------------------- //
|
||||||
|
|
||||||
|
public static boolean isFim(String line) { return line.compareTo("FIM") == 0; }
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------------------- //
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
|
||||||
|
ArrayList<Game> games = new ArrayList<Game>();
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------ //
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
// Read CSV file
|
||||||
|
String basefile = "/tmp/games.csv";
|
||||||
|
|
||||||
|
FileInputStream fstream = new FileInputStream(basefile);
|
||||||
|
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
|
||||||
|
|
||||||
|
// ------------------------------------ //
|
||||||
|
|
||||||
|
// Explode CSV file reading games
|
||||||
|
String line;
|
||||||
|
|
||||||
|
while((line = br.readLine()) != null) {
|
||||||
|
|
||||||
|
Game game = new Game();
|
||||||
|
|
||||||
|
game.read(line);
|
||||||
|
games.add(game);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close CSV file
|
||||||
|
fstream.close();
|
||||||
|
}
|
||||||
|
catch(IOException e) { e.printStackTrace(); }
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------------------- //
|
||||||
|
|
||||||
|
// Read .in file
|
||||||
|
Scanner scr = new Scanner(System.in);
|
||||||
|
String line = scr.nextLine();
|
||||||
|
|
||||||
|
while(true) {
|
||||||
|
|
||||||
|
if(isFim(line)) break;
|
||||||
|
|
||||||
|
int app_id = Integer.parseInt(line);
|
||||||
|
|
||||||
|
// Search game with .in id
|
||||||
|
for(Game game : games) {
|
||||||
|
|
||||||
|
if(game.getAppId() == app_id) game.print();
|
||||||
|
}
|
||||||
|
|
||||||
|
line = scr.nextLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------------------- //
|
||||||
|
|
||||||
|
scr.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------------------- //
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue