UMBC Pokemon Center Database Project

Description

Note that the programs you will be writing for Part 2a through Part 2g build on one another. You will want to attempt these parts in order. You can also feel free to save all of your work in one big file

Pokemon is a series of Japanese video games and related media such as trading cards and television programs, featuring cartoon monsters that are captured by players and trained to battle each other. In this program you will be helping to build a Pokemon database system for a Pokemon center.

To begin you will be creating a simple menu system that will allow the user to look up which Pokemon are available at your Pokemon Center. Given the following lists, write a program that asks the user for a Pokemon name. Next, find out if the Pokemon Center has that Pokemon and report the status to the user. Allow the user to continually inquire about product names until they elect to quit the program.

Here are some lists to get you started:

# Pokemon listspokemon_names = ['charmander', 'squirtle', 'bulbasaur', 'gyrados']pokemon_amounts = [3, 2, 5, 1]

Note that these lists are related to one another – both lists have the same # of elements, and the position of each element indicates its relationship with the other list. For example, we have 3 ‘charmander’ at our Pokemon center. The string ‘charmander’ exists at position 0 in the first list, which relates the value at position 0 in the second list (the integer 3).

Here’s a sample running of your program. Note that the prompt contains a number of features that we haven’t built yet. Don’t worry about these features just yet — we will be adding these in future parts of the assignment.

Welcome to the Pokemon Center!(a)dd, (r)emove, r(e)port, (s)earch by name, search by (t)ype, (l)ist or (q)uit: hello worldUnknown command, please try againWelcome to the Pokemon Center!(a)dd, (r)emove, r(e)port, (s)earch by name, search by (t)ype, (l)ist or (q)uit: sName of Pokemon to search for: pikachuWe do not have any Pikachu at the Pokemon CenterWelcome to the Pokemon Center!(a)dd, (r)emove, r(e)port, (s)earch by name, search by (t)ype, (l)ist or (q)uit: sName of Pokemon to search for: SquirtleWe have 2 Squirtle at the Pokemon CenterWelcome to the Pokemon Center!(a)dd, (r)emove, r(e)port, (s)earch by name, search by (t)ype, (l)ist or (q)uit: sName of Pokemon to search for: SQUIRTLEWe have 2 Squirtle at the Pokemon CenterWelcome to the Pokemon Center!(a)dd, (r)emove, r(e)port, (s)earch by name, search by (t)ype, (l)ist or (q)uit: sName of Pokemon to search for: CHarManDerWe have 3 Charmander at the Pokemon CenterWelcome to the Pokemon Center!(a)dd, (r)emove, r(e)port, (s)earch by name, search by (t)ype, (l)ist or (q)uit: qSee you next time!

Some considerations for this part of the program:

  • Commands are case insensitive (‘s’ and ‘S’ are both valid for ‘search’)
  • Allow the user to type in any case variation of the Pokemon name (i.e. the strings ‘CHARMANDER’ and ‘charmander’ should both work when searching for that Pokemon)
  • When reporting the name of the Pokemon you should ensure that the first character is capitalized (i.e. ‘Charmander’, ‘Squirtle’, ‘Bulbasaur’, etc.)

Part 2b

Next, extend your program so that it keeps track the “adoption fee” for each type of Pokemon. Default your adoption fees to be $100.00 for Charmander, $50.00 for Squirtle, $25.00 for Bulbasaur and $1,000.00 for Gyrados. Hint: you might want to create a new list called pokemon_fees to store this data! – once you have this information in place you should modify your program to do the following:

  • Update the search feature to include a line to report the adoption fee for each Pokemon
  • Add a new feature that lists ALL Pokemon, their amounts and their adoption fees.
  • Standard credit: Format your table so that it lines up visually so that each column is exactly 20 characters wide. Column 1 should be left aligned, and columns 2 and 3 should be right aligned.
  • Extra credit: Format the columns so that they grow based on the contents of each list. The sizing of each column should appear as follows:
    • Column 1 (‘Name’): aligned left, minimum length of 5 characters, can grow to the length of the longest string in the pokemon_names list + 1 (i.e. if ‘charmander’ is the largest string in the list with 10 characters, so the column should be formatted to 11 characters wide)
    • Column 2 (‘Amount Available’): aligned right, minimum length of 20 characters, can grow to the length of the largest integer in the pokemon_amounts list + 1 (i.e. if the largest amount is 5 the column will be formatted to 20 characters long, but if the largest amount is 9999999999999999999999999 (25 9’s) the column would be formatted to 26 characters wide)
    • Column 3 (‘Adoption Fee’): aligned right, minimum length of 15 characters, can grow to the length of the size of the largest formatted float in the pokemon_fees list + 1. For example, if the largest float in the list is 10000000000000000000.0 the formatted version (2 decimal points, comma separator) would be ”10,000,000,000,000,000,000.00′ — this string has 29 characters, meaning that the column width should be 30.

Here’s a sample running of your program (which shows the ‘standard credit’ version of the assignment)

Welcome to the Pokemon Center!(a)dd, (r)emove, r(e)port, (s)earch by name, search by (t)ype, (l)ist or (q)uit: sName of Pokemon to search for: squirtleWe have 2 Squirtle at the Pokemon CenterIt will cost $50.00 to adopt this PokemonWelcome to the Pokemon Center!(a)dd, (r)emove, r(e)port, (s)earch by name, search by (t)ype, (l)ist or (q)uit: lName                    Amount Available        Adoption FeeCharmander                             3              100.00Squirtle                               2               50.00Bulbasaur                              5               25.00Gyrados                                1            1,000.00Welcome to the Pokemon Center!(a)dd, (r)emove, r(e)port, (s)earch by name, search by (t)ype, (l)ist or (q)uit: qSee you next time!

Part 2c

Next, add in the ability to keep track of the “type” of each Pokemon. Each Pokemon has one or more “type” associated with it. For example, Charmander is of type “Fire”, Squirtle is of type “Water”, Bulbasaur is of type “Grass” and Gyrados has two types – “Water” and “Flying”. The following list contains these types organized for each of the 4 Pokemon you currently have in your center:

pokemon_types = [['fire'], ['water'], ['grass'], ['water', 'flying']]

Note how this is a “list of lists” – element 0 of the list is the little list [‘fire’]; element 1 of the list is the little list [‘grass’], and so on. We refer to this as a ‘multi-dimensional’ list in computer programming. You can access lists inside of lists by using more than one set of square brackets. For example, to extract the value ‘water’ from the list above you can do the following:

print(pokemon_types[3][0])

Your task is to incorporate this list into your program and report the “type” of each Pokemon when using the “search” and “list” features. Note that you probably don’t need to format these types because they will be the last thing that you print on each line of output when using the “search” feature.

Here’s a sample running of your program with these features added:

Welcome to the Pokemon Center!(a)dd, (r)emove, r(e)port, (s)earch by name, search by (t)ype, (l)ist or (q)uit: sName of Pokemon to search for: SquirtleWe have 2 Squirtle at the Pokemon CenterIt will cost $50.00 to adopt this PokemonSquirtle has the following types: Water Welcome to the Pokemon Center!(a)dd, (r)emove, r(e)port, (s)earch by name, search by (t)ype, (l)ist or (q)uit: sName of Pokemon to search for: GYRADOSWe have 1 Gyrados at the Pokemon CenterIt will cost $1,000.00 to adopt this PokemonGyrados has the following types: Water Flying Welcome to the Pokemon Center!(a)dd, (r)emove, r(e)port, (s)earch by name, search by (t)ype, (l)ist or (q)uit: lName                    Amount Available        Adoption Fee Type(s)Charmander                             3              100.00 Fire Squirtle                               2               50.00 Water Bulbasaur                              5               25.00 Grass Gyrados                                1            1,000.00 Water Flying Welcome to the Pokemon Center!(a)dd, (r)emove, r(e)port, (s)earch by name, search by (t)ype, (l)ist or (q)uit: qSee you next time!

Note that for the “list” feature you are adding a new column. This column should be left aligned and doesn’t need to be formatted to a specific size (it’s the last column in the table and nothing comes after it)

Part 2d

Next build in a feature that allows the user to search by type of Pokemon. The program should find all Pokemon of that type and display it using the “list” interface that you built above. Hint: you might want to copy the code you wrote for that part and make some changes to it to handle this new feature. The same column sizing rules apply for this (20 characters for standard credit, dynamic sizing for extra credit). Here’s a sample running of this part of the program:

Welcome to the Pokemon Center!(a)dd, (r)emove, r(e)port, (s)earch by name, search by (t)ype, (l)ist or (q)uit: tEnter Pokemon type: poisonWe have no Pokemon of that type at our Pokemon CenterWelcome to the Pokemon Center!(a)dd, (r)emove, r(e)port, (s)earch by name, search by (t)ype, (l)ist or (q)uit: tEnter Pokemon type: fireName                    Amount Available        Adoption Fee Type(s)Charmander                             3              100.00 Fire Welcome to the Pokemon Center!(a)dd, (r)emove, r(e)port, (s)earch by name, search by (t)ype, (l)ist or (q)uit: tEnter Pokemon type: waterName                    Amount Available        Adoption Fee Type(s)Squirtle                               2               50.00 Water Gyrados                                1            1,000.00 Water Flying Welcome to the Pokemon Center!(a)dd, (r)emove, r(e)port, (s)earch by name, search by (t)ype, (l)ist or (q)uit: qSee you next time!

Part 2e

Next, add in an “add” feature that lets users add a new Pokemon to the center. When you add a product you will need to ask the user for the name of the Pokemon, the adoption fee and how many Pokemon the Center has available to sell. Validate this data – you cannot add a Pokemon that already exists and both the cost and amount must be positive.

In addition, the “type” must also be validated to be one of a small number of possible types. Here are all possible valid types for the purpose of your program:

valid_pokemon_types = ['bug', 'dark', 'dragon', 'electric', 'fairy', 'fighting', 'fire', 'flying', 'ghost', 'grass', 'ground', 'ice', 'normal', 'poison', 'psychic', 'rock', 'steel', 'water']

Your program should allow the user type in multiple ‘types’ for each Pokemon. If the user requests it they should be able to access this list to see the valid types they can supply for a Pokemon. Use a sentinel value of “end” to stop accepting new Pokemon types. Hint: use an empty list to store your Pokemon types.

Here’s a sample running of the program with this feature:

Welcome to the Pokemon Center!(a)dd, (r)emove, r(e)port, (s)earch by name, search by (t)ype, (l)ist or (q)uit: lName                    Amount Available        Adoption Fee Type(s)Charmander                             3              100.00 Fire Squirtle                               2               50.00 Water Bulbasaur                              5               25.00 Grass Gyrados                                1            1,000.00 Water Flying Welcome to the Pokemon Center!(a)dd, (r)emove, r(e)port, (s)earch by name, search by (t)ype, (l)ist or (q)uit: aEnter name of new pokemon: squirtleDuplicate name, add operation cancelledWelcome to the Pokemon Center!(a)dd, (r)emove, r(e)port, (s)earch by name, search by (t)ype, (l)ist or (q)uit: aEnter name of new pokemon: ButtERFreeHow many of these Pokemon are you adding? -5Invalid, please try againHow many of these Pokemon are you adding? -3Invalid, please try againHow many of these Pokemon are you adding? 3What is the adoption fee for this Pokemon? -50.72Invalid, please try againWhat is the adoption fee for this Pokemon? 0Invalid, please try againWhat is the adoption fee for this Pokemon? 25.12Next you will be prompted to enter the 'types' for this Pokemon.  Pokemon can have multiple types. Type 'help' to view all possible Pokemon types, and type 'end' to stop entering types. You must enter at least one valid 'type'What type of Pokemon is this? help* bug* dark* dragon* electric* fairy* fighting* fire* flying* ghost* grass* ground* ice* normal* poison* psychic* rock* steel* waterWhat type of Pokemon is this? invisibleThis is not a valid type, please try againWhat type of Pokemon is this? flyingType flying addedWhat type of Pokemon is this? BUGType bug addedWhat type of Pokemon is this? endPokemon Added!Welcome to the Pokemon Center!(a)dd, (r)emove, r(e)port, (s)earch by name, search by (t)ype, (l)ist or (q)uit: lName                    Amount Available        Adoption Fee Type(s)Charmander                             3              100.00 Fire Squirtle                               2               50.00 Water Bulbasaur                              5               25.00 Grass Gyrados                                1            1,000.00 Water Flying Butterfree                             3               25.12 Flying Bug Welcome to the Pokemon Center!(a)dd, (r)emove, r(e)port, (s)earch by name, search by (t)ype, (l)ist or (q)uit: qSee you next time!

Part 2f

Next, add in a “remove” feature that lets users remove Pokemon from the database. Here’s a sample running of the program:

Welcome to the Pokemon Center!(a)dd, (r)emove, r(e)port, (s)earch by name, search by (t)ype, (l)ist or (q)uit: aEnter name of new pokemon: weedleHow many of these Pokemon are you adding? 5What is the adoption fee for this Pokemon? 72.15Next you will be prompted to enter the 'types' for this Pokemon.  Pokemon can have multiple types. Type 'help' to view all possible Pokemon types, and type 'end' to stop entering types. You must enter at least one valid 'type'What type of Pokemon is this? bugType bug addedWhat type of Pokemon is this? poisonType poison addedWhat type of Pokemon is this? endPokemon Added!Welcome to the Pokemon Center!(a)dd, (r)emove, r(e)port, (s)earch by name, search by (t)ype, (l)ist or (q)uit: lName                    Amount Available        Adoption Fee Type(s)Charmander                             3              100.00 Fire Squirtle                               2               50.00 Water Bulbasaur                              5               25.00 Grass Gyrados                                1            1,000.00 Water Flying Weedle                                 5               72.15 Bug Poison Welcome to the Pokemon Center!(a)dd, (r)emove, r(e)port, (s)earch by name, search by (t)ype, (l)ist or (q)uit: rEnter name of Pokemon to remove: pikachuPokemon not found, cannot removeWelcome to the Pokemon Center!(a)dd, (r)emove, r(e)port, (s)earch by name, search by (t)ype, (l)ist or (q)uit: lName                    Amount Available        Adoption Fee Type(s)Charmander                             3              100.00 Fire Squirtle                               2               50.00 Water Bulbasaur                              5               25.00 Grass Gyrados                                1            1,000.00 Water Flying Weedle                                 5               72.15 Bug Poison Welcome to the Pokemon Center!(a)dd, (r)emove, r(e)port, (s)earch by name, search by (t)ype, (l)ist or (q)uit: rEnter name of Pokemon to remove: squirtlePokemon removedWelcome to the Pokemon Center!(a)dd, (r)emove, r(e)port, (s)earch by name, search by (t)ype, (l)ist or (q)uit: lName                    Amount Available        Adoption Fee Type(s)Charmander                             3              100.00 Fire Bulbasaur                              5               25.00 Grass Gyrados                                1            1,000.00 Water Flying Weedle                                 5               72.15 Bug Poison Welcome to the Pokemon Center!(a)dd, (r)emove, r(e)port, (s)earch by name, search by (t)ype, (l)ist or (q)uit: rEnter name of Pokemon to remove: squirtlePokemon not found, cannot removeWelcome to the Pokemon Center!(a)dd, (r)emove, r(e)port, (s)earch by name, search by (t)ype, (l)ist or (q)uit: rEnter name of Pokemon to remove: weedlePokemon removedWelcome to the Pokemon Center!(a)dd, (r)emove, r(e)port, (s)earch by name, search by (t)ype, (l)ist or (q)uit: lName                    Amount Available        Adoption Fee Type(s)Charmander                             3              100.00 Fire Bulbasaur                              5               25.00 Grass Gyrados                                1            1,000.00 Water Flying Welcome to the Pokemon Center!(a)dd, (r)emove, r(e)port, (s)earch by name, search by (t)ype, (l)ist or (q)uit: qSee you next time!

Part 2g

Finally, add in a reporting feature to your program that finds the highest priced Pokemon, the lowest priced Pokemon and the total cost to adopt all Pokemon in the center (Pokemon cost * Pokemon quantity). Here’s a sample running of your program:

Welcome to the Pokemon Center!(a)dd, (r)emove, r(e)port, (s)earch by name, search by (t)ype, (l)ist or (q)uit: lName                    Amount Available        Adoption Fee Type(s)Charmander                             3              100.00 Fire Squirtle                               2               50.00 Water Bulbasaur                              5               25.00 Grass Gyrados                                1            1,000.00 Water Flying Welcome to the Pokemon Center!(a)dd, (r)emove, r(e)port, (s)earch by name, search by (t)ype, (l)ist or (q)uit: eHighest priced Pokemon: Gyrados @ $1,000.00 per PokemonLowest priced Pokemon: Bulbasaur @ $25.00 per PokemonTotal cost to adopt all Pokemon in the Center: $1,525.00Welcome to the Pokemon Center!(a)dd, (r)emove, r(e)port, (s)earch by name, search by (t)ype, (l)ist or (q)uit: aEnter name of new pokemon: mewHow many of these Pokemon are you adding? 7What is the adoption fee for this Pokemon? 25000.00Next you will be prompted to enter the 'types' for this Pokemon.  Pokemon can have multiple types. Type 'help' to view all possible Pokemon types, and type 'end' to stop entering types. You must enter at least one valid 'type'What type of Pokemon is this? psychicType psychic addedWhat type of Pokemon is this? endPokemon Added!Welcome to the Pokemon Center!(a)dd, (r)emove, r(e)port, (s)earch by name, search by (t)ype, (l)ist or (q)uit: lName                    Amount Available        Adoption Fee Type(s)Charmander                             3              100.00 Fire Squirtle                               2               50.00 Water Bulbasaur                              5               25.00 Grass Gyrados                                1            1,000.00 Water Flying Mew                                    7           25,000.00 Psychic Welcome to the Pokemon Center!(a)dd, (r)emove, r(e)port, (s)earch by name, search by (t)ype, (l)ist or (q)uit: eHighest priced Pokemon: Mew @ $25,000.00 per PokemonLowest priced Pokemon: Bulbasaur @ $25.00 per PokemonTotal cost to adopt all Pokemon in the Center: $176,525.00Welcome to the Pokemon Center!(a)dd, (r)emove, r(e)port, (s)earch by name, search by (t)ype, (l)ist or (q)uit: rEnter name of Pokemon to remove: bulbasaurPokemon removedWelcome to the Pokemon Center!(a)dd, (r)emove, r(e)port, (s)earch by name, search by (t)ype, (l)ist or (q)uit: eHighest priced Pokemon: Mew @ $25,000.00 per PokemonLowest priced Pokemon: Squirtle @ $50.00 per PokemonTotal cost to adopt all Pokemon in the Center: $176,400.00Welcome to the Pokemon Center!(a)dd, (r)emove, r(e)port, (s)earch by name, search by (t)ype, (l)ist or (q)uit: qSee you next time!

Remember that you only need to submit the final part of this assignment (part G) which will include the functionality of all of the previous parts.

Python Project Paper

Description

Up until now, we have given you fairly detailed instructions for how to design data analyses to answer specific questions about data — in particular, how to set up a particular analysis and what steps to take to run it. In this project, you will put that knowledge to use!

Put yourself in the shoes of a data scientist that is given a data set and is asked to draw conclusions from it. Your job will be to understand what the data is showing you, design the analyses you need, justify those choices, draw conclusions from running the analyses, and explain why they do (or do not) make sense.

We are deliberately not giving you detailed directions on how to solve these problems, but feel free to come to office hours to brainstorm.

Objectives

There are two possible paths through this project:

  1. You may use data set #1, which captures information about bike usage in New York City. See below for the analysis questions we want you to answer.
  2. You may use data set #2, which captures information about student behavior and performance in an online course. See below for the analysis questions we want you to answer.

Note that you can select EITHER data set #1 or data set #2, but you should NOT complete the mini-project for both dataset.

We have provided starter codes to help you load the data to your environment using MiniProjectPath1.py and MiniProjectPath2.py for paths 1 and 2 respectively. The code provided is supplemental material to help you with with the data loading process, however feel free to choose a different method to read the data. It is not mandatory to use this code.

In your final report, you are expected to answer the questions asked below corresponding to your chosen dataset. For both data sets, please begin by including a section on descriptive statistics (see details below). In addition, please justify why you chose to use certain methods and models to answer the questions (for the most part, there will not be incorrect answers regarding a particular model as long as your reasoning is explained).

Descriptive statistics

For the descriptive statistics task, you need to summarize your dataset. This description will help you be more knowledgeable of your dataset and intentional in choosing your methods of data analysis when answering the questions. The description should include, but is not limited to (i.e., feel free to include more descriptive statistics than what is asked below, but not less):

  1. What are the variables in your dataset? What do they mean (describe the variables that you plan to use)?
  2. After reading the questions for the data set you have chosen to work with, provide a summary statistics table of the variables you will use. If you need to transform a variable (e.g., Precipitation into a Raining or not raining variable), this variable must be included in the table. You can use any appropriate summary statistics (e.g., mean, standard deviation, mode).
  3. Provide a histogram and explain the resulting plot for at least one variable in your dataset

Descriptive statistics should be included in both paths.

Path 1: Bike traffic

The NYC_Bicycle_Counts_2016_Corrected.csv gives information on bike traffic across a number of bridges in New York City. In this path, the analysis questions we would like you to answer are as follows:

  1. You want to install sensors on the bridges to estimate overall traffic across all the bridges. But you only have enough budget to install sensors on three of the four bridges. Which bridges should you install the sensors on to get the best prediction of overall traffic?
  2. The city administration is cracking down on helmet laws, and wants to deploy police officers on days with high traffic to hand out citations. Can they use the next day’s weather forecast (low/high temperature and precipitation) to predict the total number of bicyclists that day?
  3. Can you use this data to predict whether it is raining based on the number of bicyclists on the bridges (hint: The variable raining or not raining is binary)?

Path 2: Student performance related to video-watching behavior

behavior-performance.txt contains data for an online course on how students watched videos (e.g., how much time they spent watching, how often they paused the video, etc.) and how they performed on in-video quizzes. readme.pdf details the information contained in the data fields. There might be some extra data fields present than the ones mentioned here. Feel free to ignore/include them in your analysis. In this path, the analysis questions we would like you to answer are as follows:

(For Q2,Q3: You will run prediction algorithm(s) for ALL students for ONE video, and repeat this process for all videos. The function get_by_VidID in the helper file MiniProjectPath2 will help you in this process.)

  1. How well can the students be naturally grouped or clustered by their video-watching behavior (fracSpent, fracComp, fracPaused, numPauses, avgPBR, numRWs, and numFFs)? You should use all students that complete at least five of the videos in your analysis. Hints: Would KMeans or Gaussian Mixture Models be more appropriate? Consider using both and comparing.
  2. Can student’s video-watching behavior be used to predict a student’s performance (i.e., average score s across all quizzes)?(hint: Just choose 1 – 4 data fields to create your model. We are looking at your approach rather than model performance.)
  3. Taking this a step further, how well can you predict a student’s performance on a particular in-video quiz question (i.e., whether they will be correct or incorrect) based on their video-watching behaviors while watching the corresponding video? You should use all student-video pairs in your analysis.

What to turn in

You must turn in two sets of files by pushing them to your team’s Github repository:

  • report.pdf: A project report, which should consist of:
    • A section with the names of the team members (maximum of two), your Purdue username(s), and the path (1 or 2) you have taken. Use the heading “Project team information”.
    • A section stating and describing the dataset you are working with. Use the heading “Descriptive Statistics”.
    • A section describing the methods of data analysis you chose to use for each analysis question (with a paragraph or two justifying why you chose that method and what you expect the analysis to tell you). Use the heading “Approach”.
    • A section describing the results of each method/analysis, and what your answers to the questions are based on your results. At list one visual aid should be included (you can use many if necessary to back up your conclusions). Nonetheless, any visual included should be mentioned in the text. Note that it is OK if you do not get a “close” answer/answers from your analysis, but you must explain why that might be. Here, you should essentially be answering the questions asked above for your chosen data set. Use the heading “Analysis”.
  • All Python .py code files you wrote to complete the analysis steps. In addition, the report must be a PDF file. See the template provided to guide yourself on the format of the project. Not complying with the instructions might result in a deduction of points.Up until now, we have given you fairly detailed instructions for how to design data analyses to answer specific questions about data — in particular, how to set up a particular analysis and what steps to take to run it. In this project, you will put that knowledge to use!Put yourself in the shoes of a data scientist that is given a data set and is asked to draw conclusions from it. Your job will be to understand what the data is showing you, design the analyses you need, justify those choices, draw conclusions from running the analyses, and explain why they do (or do not) make sense.We are deliberately not giving you detailed directions on how to solve these problems, but feel free to come to office hours to brainstorm.

CSC 316 Simply a Sequential Stream of Bytes Question

Description

Write a program to count spaces, tabs (/t), and newlines of the file “data.txt”.


CSC 316 Lab 10: System I/O and File Handling

Submit your C code on Canvas before the deadline. Group discussions are encouraged for this lab assignment.
Coding Task:
Write a program to count spaces, tabs (/t), and newlines of the file “data.txt”.

Study the code examples using C standard I/O functions from the last lecture and
the examples below.
Example 1: The getc() function
The getc() function reads a single character from the input stream (a file) at the current
position and increases the stream position to the next character. The getc() function
returns the character that is read as an integer. A return value of EOF indicates an error
or endoffile condition.

Syntax:
#include <stdio.h>
int getc(FILE *fp);

Code example: the following program reads a file and prints its first line to the screen.
/***********************************************************************
This code reads and prints the first line from a file.
************************************************************************/
#include <stdio.h>
#defineMAX_LEN 800

void main()
{
FILE *fp;
char buffer[MAX_LEN + 1];
int i, ch;
fp = fopen(“./data.txt”,“r”);
for (i = 0; (i<(sizeof(buffer)1) && ((ch = getc(fp)) != EOF) && (ch != n)); i++)
{
buffer[i] = ch;
}

buffer[i] = 0;
if (fclose(fp))
{
perror(“fclose error”);
}
printf(“The first line is: %sn, buffer);
}

Example 2: The fgets() function
The fgets() function reads a line of text from a stream (a file) one character at a time,
stopping at newline character (n), or up to the end of the stream, or until the number
of characters read is equal to n1, whichever comes first. The fgets() function stores
the result in string and adds a null character (0) to the end of the string.
The string includes the newline character, if read. If n is equal to 1, the string is empty.

The fgets() function returns a pointer to the string buffer if successful. A NULL return
value indicates an error or an endoffile condition.

Syntax:
#include <stdio.h>
char *fgets(char *string, int n, FILE *fp);

Code example: the following program compares two files, printing the first line where
they differ.
/***********************************************************************
This code compares two files, printing the first line where they differ.
Usage: run: ./compare file_1.txt file_2.txt
************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_LINE_LEN 1000

int parse_arg_list(int argc, char *argv[]);

int main(int argc, char *argv[])
{
if (!parse_arg_list(argc, argv))
{
fprintf(stderr, “Error: invalid arguments.n);
exit(EXIT_FAILURE);
}

char *program_name = argv[0];

FILE *fp1;
FILE *fp2;

if ((fp1 = fopen(argv[1], “r”)) == NULL)
{
fprintf(stderr, %s: can’t open %s.n, program_name, argv[1]);
exit(EXIT_FAILURE);
}

if ((fp2 = fopen(argv[2], “r”)) == NULL)
{
fprintf(stderr, %s: can’t open %s.n, program_name, argv[2]);
exit(EXIT_FAILURE);
}

char line_1[MAX_LINE_LEN];
char line_2[MAX_LINE_LEN];

size_t line_number = 1;
while (fgets(line_1,MAX_LINE_LEN,fp1)!=NULL && fgets(line_2,MAX_LINE_LEN,fp2)!=NULL)
{
if (strcmp(line_1, line_2) != 0)
{
printf(%s [%zu]: %s, argv[1], line_number, line_1);
fclose(fp1);

printf(%s [%zu]: %s, argv[2], line_number, line_2);
fclose(fp2);
break;
}

line_number++;
}
exit(EXIT_SUCCESS);
}

int parse_arg_list(int argc, char *argv[])
{
if (argc != 3)
{
return 0;
}
return 1;
}

C++ Programming Code

Description

C++ source file name: Memory.cpp

File name must be Memory.cpp

Write a program that plays a memory game with cards containing upper-case letters. The cards are laid out in a 4×4 grid with row and column indices from 0 to 3, as follows (the left diagram with the dollar signs represent the back of the card, the right diagram represents the front of the card. Note that the letters on the cards should be randomly generated from uppercase A-Z each time the game is played from the start): Download Sample program)

0 1 2 3
0 | $ | $ | $ | $
——————-
1 | $ | $ | $ | $
——————-
2 | $ | $ | $ | $
——————-
3 | $ | $ | $ | $
——————-

0 1 2 3
0 | K | M | T | P
——————-
1 | P | Y | K | X
——————-
2 | G | T | E | Y
——————-
3 | M | X | E | G
——————-

Note that each letter is represented exactly twice in the right diagram. The objective of the game is to find as many matching pairs as possible.

Each round of gameplay should do the following:

  1. Print the board. Previously matched cards should show the matched letters.
  2. Ask the player if they’d like to Find a match (F) or Quit (Q)
  3. If the player chooses Find, ask for the two cards in row, column format. Make sure that the cards are not the same card(e.g., player chooses card 1,1 and 1,1) and that neither card has already been matched. If either of these cases is true, then prompt the player to choose new cards in row, column format.
  4. After each choice, tell the player how many points they have. They get a point for every matching pair of cards.
  5. Print the player’s final number of points if they choose to Quit (Q).

If there are no cards left to play (all matches have been found) the player wins and the game should print their final points and end. See the sample outputs for more details on gameplay.

Required Functions:

You code must have at least the following two functions. The parameters passed can be different than what is shown below. You may use any other functions you wish:

<strong>void print_board(char in_board[][BOARD_SIZE]);</strong>

This function prints the current board to the screen with matched cards flipped to show their letter and unmatched cards unflipped.

<strong>void fill_board(char in_board[][BOARD_SIZE]);</strong>

This function fills the board with randomly selected uppercase letters in the range A-Z. Note that each letter generated must appear exactly twice on the board.

Your program’s output must match the output below as exactly as possible.

Scenario 1: One Round, Cards Match

(the matched cards stay flipped to their letter for the rest of the game):

Welcome to Memory Game! Here's the board:    0   1   2   30 | $ | $ | $ | $-----------------1 | $ | $ | $ | $-----------------2 | $ | $ | $ | $-----------------3 | $ | $ | $ | $-----------------Choose an option:(F) Find a match(Q) QuitChoice: <strong>F</strong>Pick first card (row, column): <strong>2,3</strong>Pick second card (row, column): <strong>1,3</strong>Cards match! You get a point!Your current points: 1Here's the board:    0   1   2   30 | $ | $ | $ | $-----------------1 | $ | $ | $ | A-----------------2 | $ | $ | $ | A-----------------3 | $ | $ | $ | $-----------------Choose an option:(F) Find a match(Q) QuitChoice: <strong>Q</strong>Your total points: 1 Goodbye!

Scenario 2: One Round, Cards Don’t Match
(the chosen cards are flipped to their letter after the non-match is announced):

Welcome to Memory Game!Here's the board:    0   1   2   30 | $ | $ | $ | $-----------------1 | $ | $ | $ | $-----------------2 | $ | $ | $ | $-----------------3 | $ | $ | $ | $-----------------Choose an option:(F) Find a match(Q) QuitChoice: <strong>F</strong>Pick first card (row, column): <strong>2,2</strong>Pick second card (row, column): <strong>1,3</strong>Cards do not match! Try again!Here's the board:    0   1   2   30 | $ | $ | $ | $-----------------1 | $ | $ | $ | X-----------------2 | $ | $ | B | $-----------------3 | $ | $ | $ | $-----------------Choose an option:(F) Find a match(Q) QuitChoice: <strong>Q</strong>Your total points: 0 Goodbye!

Scenario 3: Multiple Rounds, Some Matches, Some Non-Matches:
(matched cards stay flipped to their letter, but non-matched go back to the $ after they’re shown):

Welcome to Memory Game!Here's the board:    0   1   2   30 | $ | $ | $ | $-----------------1 | $ | $ | $ | $-----------------2 | $ | $ | $ | $-----------------3 | $ | $ | $ | $-----------------Choose an option:(F) Find a match(Q) QuitChoice: <strong>F</strong>Pick first card (row, column): <strong>3,1</strong>Pick second card (row, column): <strong>2,2</strong>Cards match! You get a point!Your current points: 1Here's the board:    0   1   2   30 | $ | $ | $ | $-----------------1 | $ | $ | $ | $-----------------2 | $ | $ | W | $-----------------3 | $ | W | $ | $-----------------Choose an option:(F) Find a match(Q) QuitChoice: <strong>F</strong>Pick first card (row, column): <strong>0,2</strong>Pick second card (row, column): <strong>1,1</strong>Cards do not match! Try again!Here's the board:    0   1   2   30 | $ | $ | K | $-----------------1 | $ | Q | $ | $-----------------2 | $ | $ | W | $-----------------3 | $ | W | $ | $-----------------Choose an option:(F) Find a match(Q) QuitChoice: <strong>F</strong>Pick first card (row, column): <strong>3,2</strong>Pick second card (row, column): <strong>2,3</strong>Cards do not match! Try again!Here's the board:    0   1   2   30 | $ | $ | $ | $-----------------1 | $ | $ | $ | $-----------------2 | $ | $ | W | X-----------------3 | $ | W | P | $-----------------Choose an option:(F) Find a match(Q) QuitChoice: <strong>Q</strong>Your total points: 1Goodbye!

Submissions will be screened for plagiarism and other academically dishonest practices so you MUST do entirely your own work. You may help each other to understand and mathematically grasp the problems, but all submitted work must be unique and original. Please submit your assignment by the due date to the Assignment 3 location in Canvas.

Note: There are MANY solutions to this assignment online. Using these solutions too heavily, like copying and pasting parts or entire code solutions, is also considered Plagiarism.

MAR 3721 University of Alberta Website Publishing WordPress Task

Description

Required:

Website Pages (50 points)

-Home Page 10 points
– About Page (with personal photo and bio) 15 points
*This is required for me to grade your assignment any assignment submitted without this page will lose one letter grade for every day it is without this*
– Contact Page 10 points
*page itself worth 5 points, functioning contact form worth 5 points*

– An minimum of 1 additional page 15 points
(Depending on you proposal: either blog, product, eCommerce, pricing or services depending on your proposal)

Design (150 Points)

The following sections will be graded on a sliding scale of 1-10 points

Content (maximum 30 points):

You can get up to 30 points for this category. Please keep in mind the following:

  • Your website should have a clear and well-stated purpose and them.
  • Punctuation, grammar, and spelling errors should not be present.
  • Your website should not see bare. There should be sufficient content (text, photos, videos, etc.) for the number of pages you have o your website
  • You should maintain the same language (tense, first or third person, etc.) throughout your site.
  • Content is organized in a way that makes sense in site navigation.
  • Social handles are linked/interactive website elements are present. (forms, comments, likes, shares, etc.)

Layout (maximum 30 points):

You can get up to 30 points for this category. Please keep in mind the following:

  • The website should not be cluttered or difficult to navigate. Your layout should not appear busy or boring.
  • White space/blank spaces should be balanced with there not being too much or too little.
  • It should be simple to locate important elements.
  • Your layout should be exceptionally attractive and easy to use to achieve the most points in this category
  • Graphics should be organized effectively.
  • Text and image alignment should be consistent resulting in a polished overall site.
  • Website has a header and footer where necessary.
  • Website is mobile responsive.

Fonts (maximum 30 points):

You can get up to 30 points for this category. Please keep in mind the following:

  • Fonts should be easy to read.
  • Sizes of fonts and points are consistent and vary appropriately for headings and text.
  • Bold/Italics/Color are used thoughtfully to enhance text content
  • Titles, headers, subheaders, and block text should all have their own styles and be consistent throughout the site
  • Fonts should not be too small nor too big. I recommend at least size 12pt font.
  • Overall fonts add to readability as well as enhance the overall theme of the website.

Graphics (maximum 30 points):

You can get up to 30 points for this category. Please keep in mind the following:

  • Website has a personal photo in at least one place.
  • Graphics should not seem randomly chosen, low quality, and distracting.
  • Graphics should be related to the theme/purpose of the site and are high quality.
  • Graphics should not be pixelated.
  • Overall “Style” of graphics should be consistent throughout the site
  • Images should not be too large or too small
  • Images (where necessary) link to appropriate pages.
  • Social media icons (if used) are not pixelated and match their respective links
  • Images should be consistently aligned and cropped with one another to make the site visually appealing.
  • Graphics are thoughtfully cropped, not pixelated and enhance the user experience and overall understanding of the website.

Navigation (maximum 30 points):

You can get up to 30 points for this category. Please keep in mind the following:

  • Links for navigation are clearly labeled, allowing the user to easily move from page to page and internal links take the user where they expect to go.
  • Links for navigation are consistently placed in the header/footer, allowing the user to easily move from page to page
  • Social media ( if used) is integrated successfully.
  • Email functionality opens properly
  • CTAs are used thoughtfully
  • In text links are used when appropriate.
  • Citations are provided where necessary and use links appropriately.
  • All external links open in new tabs
  • All internal site links DO NOT open in new tabs
  • Website forms provide confirmation of form submission
  • create an email in MailChimp (Links to an external site.). Your email can be about any subject you’d like. You can make a newsletter, promote your favorite product or brand, or tie your content back to your website. The only thing you MUST DO is include your name at the bottom of your email so that I know it is from you. I will not grade any emails that I cannot identify the sender.Follow the steps to create an account and create an email. Send your email to by 11:59 PM on April 25th. You can also upload a file version or the webpage version of your email at this link. Your email can be any of the 6 types of email marketing we went over in class, except for a Transactional Email.NewslettersLead NurturingInformationalTransactional (Do not use this type of email for this assignment)Content AnnouncementProduct UpdateThis assignment is worth 30 points. You will be graded as follows:Subject Line (5 points)Your subject line should be relevant or clever to receive all 5 points for this category.Be sure to follow best practices:Grab the attention of your readers in as few words as possible (less is more). I recommend no more than 9 words and 60 characters.Provide some sort of value and/ or information that makes them want to open the email.Summarize what recipients are going to read and/ or see once they open the email.User-Friendly Design and Consistent “Brand” (10 points)With email design, consistency is key. There should be a consistent design and tone throughout your email to receive all 10 points for this category.Your layout should be user-friendly and easy to follow.Your email shouldn’t feel cluttered or unorganized.CTAs, links, and social icons should take your reader where they expect to go.Be sure to follow best practices:To maintain your brand voice and appearance through your marketing email, be sure to use a consistent tone through your email content, your social accounts, and your website. Incorporate the same colors and fonts in your email design as you have across all platforms as well.Organize your layout with an eye on user experience (UX).Use a responsive design.Text and Image Content (15 points)To receive all 15 points for this category your email should have clear language that is easy to follow and understand. Copy should be enticing and interesting to read.Font sizes and styles should be easy to read.Images should be thoughtfully chosen, cropped, and placed in the email.Images should not be pixelated, too large, or too small.Leave white space and strategically place your written and visual content in the email so it’s organized and easy to navigate.

Python Programming Project

Description

This homework asks you to fill in portions of classes that you can then use to perform k-means analysis.

Goals

In this assignment you will:

  • Get familiar with using objects and classes by defining some methods and using objects to perform a computation
  • Implement k-means
  • Get practice with implementing Gaussian Misture Models (GMMs) using sklearn

Background

Classes and Objects

Please see the class notes on objects and classes on Brightspace.

k-means and GMMs

Please see the class notes on clustering and specifically k-means and GMMs on Brightspace.

Instructions

0) Set up your repository for this homework.

Use the link on Piazza to set up Homework 9.

The repository should contain the following files:

  1. This README.
  2. cluster.py which contains the definition of the Cluster class and some testing code.
  3. point.py which contains the definition of the Point class and some testing code.
  4. kmeans.py which contains the skeleton of the k-means algorithm and some testing code.
  5. gmm.py which contains the skeleton of the gaus_mixture() function.
  6. gmm_data.csv which contains the data that will be used to test your GMM function.

1) Homework Problem 1: Complete Point class

Complete the missing portions of the Point class, defined in point.py:

  1. distFrom, which calculates the (Euclidean) distance between the current point and the target point. Be sure to account for the fact that a point may be in more than two dimensions (Euclidean distance generalizes: square the difference in each dimension and take the square root of the sum). It is okay to use math.sqrt() to calculate the square root.
  2. makePointList, which takes in a data p-by-k input matrix data and returns a list of p Point objects. Hint: Instantiate a point object for every row in the input, data. Note that makePointList is outside the Point class.

If you test your code by running python3 point.py, you should get the following:

[Point([0.5 2.5]), Point([0.3 4.5]), Point([-0.5  3. ]), Point([0.  1.2]), Point([10. -5.]), Point([11.  -4.5]), Point([ 8. -3.])]2.009975124224178

(Your floating point numbers may be a little off due to rounding)

2) Homework Problem 2: Complete Cluster class

Complete the missing portions of the Cluster class, defined in cluster.py:

  1. avgDistance, which computes the average distance from the center of the cluster (stored in self.center) to all of the points currently in the cluster (stored in self.points). This can most easily be done by summing the distances between each point and the current center and then dividing the sum by the total number of points.
  2. updateCenter, which updates the center of the cluster (stored in self.center) to be the average position of all the points in the cluster. Note that if there are no points in the cluster, you should return without updating (i.e., if there are no points, just return).

Note that we have defined dim and coords as properties that return information about the center of the cluster — this means that if you pass a cluster into a method that is expecting a point, operations that access dim and coords will use the center of the cluster. Think about how that might be useful in conjunction with the closest method defined for Point.

If you test your code by running python3 cluster.py, you should get the following:

Cluster: 0 points and center = [0.5, 3.5]Cluster: 2 points and center = [0.5, 3.5]1.4976761962286425Cluster: 2 points and center = [1.75, 2.75]0.3535533905932738

(Your floating point numbers may be a little off due to rounding)

3) Homework Problem 3: Implement k-means

Use the methods in Point and Cluster to implement the missing kmeans method in kmeans.py. The basic recommended procedure is outlined in kmeans.py.

If you test your code by running python3 kmeans.py, you should get the following:

Cluster: 4 points and center = [0.075 2.8  ]   [0.3 4.5]   [0.  1.2]   [0.5 2.5]   [-0.5  3. ]Cluster: 3 points and center = [ 9.66666667 -4.16666667]   [ 8. -3.]   [10. -5.]   [11.  -4.5]

Note, the order of the points in each cluster doesn’t matter (neither does the order of clusters), all that’s important is that each cluster contains the correct points. Your floating point numbers may be a little off due to rounding.

4) Homework Problem 4: Find best number of clusters to use on GMM algorithms

Note that this problem is independent of the three problems above. In addition, you are permitted to use the GMM implementation in the sklearn library.

Here, you will complete the function gaus_mixture() in gmm.py. Given a 1-d array of data and a list of candidate cluster numbers as input, the function should return the best number of clusters to use (from the input list of candidate cluster numbers) on the GMM.

The best number of clusters is determined by (1) fitting a GMM model using a specific number of clusters, (2) calculating its corresponding Bayes Information criterion (BIC – see formula below), and then (3) setting the number of clusters corresponding to the lowest BIC as the best number of clusters to use.

This function should be completed using the algorithm outlined in the skeleton code. In addition, consider the following hints:

  1. The GMM algorithm can be implemented using the sklearn library using gm = GaussianMixture(n_components=d, random_state=0).fit(dataset), where d corresponds to the number of clusters to use and dataset is a (for our case) n-by-1 array of data. Lastly, random_state=0 is a random seed that allows for reproducibility. In your code, you must set random_state=0 when you call GaussianMixture.
  2. The BIC formula is given by BIC = -2log(L) + log(N)d, where L is the maximum likelihood of the model, d is the number of parameters, and N is the number of data samples. When using the sklearn library, however, the BIC is given by bic = gm.bic(dataset), where gm is the object returned when GaussianMixture() from Hint 1 is instantiated. gm.bic is how the BIC should be calculated in your implementation.

When you run your code on the given data in gmm_data.csv using n_components=[2, 3, 4, 6, 7, 8] as the possible number of clusters, your output should be:

Best fit is when k = 3 clusters are used

What you need to submit

Push your completed versions of kmeans.py, cluster.py, point.py, and gmm.py.

Functions Dictionary Import Files Project

Description

Topics: Functions, Dictionary, Import, Files 

Problem description: Write a python application to simulate an online clothing system. The purpose of this assignment is to gain experience in Python dictionary structure, create basic Python functions and import a module. This homework is based on Homework – 3 and will be a helpful resource for your final project. This program is similar to HA-3 the only difference is that it uses files read operation along with dictionary data structure. 

Design solution: An input file input_HA4.txt is given – contains clothes item sold, one item per line and each line contains the item id, name of the item and the prices. The program will generate an items dictionary where each key is the item id of the cloth and the values will be a list of item name and price information from reading the file information. A customer will be presented with a main menu with 4 different options: display all items, add an item to cart by ID, purchase item by price range, checkout and exit the program. A customer can buy an item by entering the ID of the item. This program implements a dictionary called cart, where each key is the item id and the values are the list of name, price and quantity that user chooses to purchase. The program keeps repeating by displaying the main menu to user until user hits the exit button. If user hits the checkout option, the program will display all the items in the cart and display the total amount purchased. Implementation: 

1. This program will require to use two .py files: utility and application files. utility file contains all the helper functions. The application file contains the main functionality of the program. One helpful example can be: how to import a module discussed so far.

2. This program requires to implement two dictionaries: items and cart. items will be populated from the given input file at the beginning of the program. Each key will be the item id and the value will be a list of item name and price. cart dictionary will be a subset of items dictionary that contains all the items user wants to purchase. The structure will be same as items dict except the value list will contain name, price and quantity of the item.

3. The application file will contain a main function. main function implements the user menu and calls all the functions from the utility file. Hint: How to import a function from one file to another? 

4. Utility file will contain the following function definitions. All these function call will be made from application file.

a. build_dict(): Returns items dict from input_HA4.txt input file. read each line of the file, separate the information to identify the key and value to add an item to the items dictionary. This function to be defined in the utility file and will be called from the application file at the beginning of the program. 

b. checkout(cart): Returns the total amount purchased using the user cart. This function will be called when user chooses to checkout. cart contains all the items user is purchasing. checkout function will get the price and quantity of an item from the cart dictionary and returns the total amount by multiplying price with quantity. Hint: price of an item is the -2 index and quantity at -1 index from the cart’s value list.

c. display_all_items(d): Takes any dictionary d and display all the items in the dictionary. This function will be called for purchasing options. Hint: How to print a dictionary using a for loop?

d. add_to_cart_by_ID(user_id, user_quantity, cart, items): Add an item to cart from the items dict if item id exists. User will provide the item id. If it exists then item will be added to the cart. Upon successful addition the function will return True otherwise returns False. 

e. display_item_by_price_range(min_price, max_price, items): display an item if it falls withing the user given price from the items dict. It will return True if items are found within the range otherwise returns False. Same as HA-3 implementation except using a dictionary. 

Sample I/O: 

Welcome to Shopping IT109!

**** Following items are available in the store **** 

ID-Item name-Price

ID1-AX Jacket-202.99

ID100-RL Polo-60.99

ID23-AK Tops- 19.99 

ID34-Levis Jeans-65.78

[id] Purchase item by name

[p] Purchase item by price range 

[c] Checkout Please input an option or type ‘e’ to exit the program: p

Enter min price: 10

Enter max price: 70

ID100-RL Polo-60.99

ID23-AK Tops- 19.99

ID34-Levis Jeans-65.78

Enter the ID of the item: ID100

Enter the quantity: 4

4 of ID100 added to your cart

**** Following items are available in the store **** 

ID-Item name-Price 

ID1-AX Jacket-202.99

ID100-RL Polo-60.99

ID23-AK Tops- 19.99

ID34-Levis Jeans-65.78 

[id] Purchase item by name 

[p] Purchase item by price range

[c] Checkout Please input an option or type ‘e’ to exit the program: ID 

Enter the ID of the item: ID34

Enter the quantity: 1

1 of ID34 added to your cart

**** Following items are available in the store ****

ID-Item name-Price

ID1-AX Jacket-202.99 

ID100-RL Polo-60.99

ID23-AK Tops- 19.99 

ID34-Levis Jeans-65.78

Please input an option or type ‘e’ to exit the program: P 

Enter min price: 300

Enter max price: 400 

No item found within the price range. #error message

[id] Purchase item by name

[p] Purchase item by price range 

[c] Checkout Please input an option or type ‘e’ to exit the program: C 

Thanks for shopping with us. 

**** You purchased the following item(s) ****

ID-Item name-Price-Quantity 

ID100-RL Polo-60.99-4

ID34-Levis Jeans-65.78-1 

The total amount is: $309.74 

**** Following items are available in the store **** 

ID-Item name-Price 

ID1-AX Jacket-202.99 

ID100-RL Polo-60.99

ID23-AK Tops- 19.99 

ID34-Levis Jeans-65.78 

[id] Purchase item by name 

[p] Purchase item by price range

[c] Checkout Please input an option or type ‘e’ to exit the program: E

>>>

This information in the txt file; 

ID1,AX Jacket,202.99

ID100,RL Polo,60.99

ID23,AK Tops, 19.99 

ID34,Levis Jeans,65.78

St Josephs University GreenHub Initiative Android Energy Consumption Analysis

Description

Description

The GreenHub initiative is a collaborative approach to Android energy consumption analysis. Its most important component is a dataset. The entries in the GreenHub dataset include multiple pieces of information, e.g., active sensors, memory usage, battery voltage, and temperature, running applications, model and manufacturer, and network details. This raw data was obtained by continuous crowdsourcing through a mobile application called BatteryHub. It is worth noting that all such data is publicly available, while maintaining the anonymity and privacy of all its users. Indeed, it is impossible to associate any data with the user who originated it. The dataset is sizable and thus far it comprises of 23+ million unique samples, including more than 700+ million data points pertaining to processes running on these devices. The dataset is also diverse. It includes data stemming from 1.6k+ different brands, 11.8k+ smartphone models, from over 50 Android versions, across 160 countries. Overall, the dataset comprises more than 120GB of uncompressed data.

For this assignment, you will have to examine a small part of this dataset, the dataset-samples part (hereafter just the “dataset-samples” dataset). It consists of multiple files, each one grouping approximately 300,000 observations collected from a number of devices. Each of these observations includes data such as the temperature of the device when the observation was collected, whether wifi was on or off, amount of free memory, cpu usage, current battery level, among others. The files are organized so that each row corresponds to one observation. The values in each observation are separated by semicolon (‘;’) and in this manner organized as columns. The first row of each file contains the labels for the columns. The following is the list of columns of each of these files:

[‘id’, ‘device_id’, ‘timestamp’, ‘battery_state’, ‘battery_level’, ‘timezone’, ‘country_code’, ‘memory_active’, ‘memory_inactive’, ‘memory_free’, ‘memory_user’, ‘charger’, ‘health’, ‘voltage’, ‘temperature’, ‘usage’, ‘up_time’, ‘sleep_time’, ‘network_status’, ‘network_type’, ‘mobile_network_type’, ‘mobile_data_status’, ‘mobile_data_activity’, ‘wifi_status’, ‘wifi_signal_strength’, ‘wifi_link_speed’, ‘screen_on’, ‘screen_brightness’, ‘roaming_enabled’, ‘bluetooth_enabled’, ‘location_enabled’, ‘power_saver_enabled’, ‘nfc_enabled’, ‘developer_mode’, ‘free’, ‘total’, ‘free_system’, ‘perform the following tasks:

0. Obtain the dataset and familiarize yourself with the data contained in the .csv files.

1.Build a function named getColumnValues() that takes as argument a list of column names and creates a NumPy array containing the values in the corresponding columns of the dataset-samples dataset, for all the files in the dataset. This function should be parameterized by the number of files to be read! The number of columns of the matrix should be the same as the list of column names received as argument. The function should return that NumPy array, filled in with the values read from the observations, for the corresponding columns.

2.Write a function named minMaxTemperatures() that receives the matrix produced by getColumnValues() as argument to determine the minimum and maximum temperatures among all the observations in the dataset. What are the ids of the devices with these values?

3.Write a function named percentageLocationEnabled() to determine what is the percentage of observations where location is enabled. Again, its argument should be a matrix produced by getColumnValues().

4.Implement a function named averageBatteryLevel() to calculate the average battery level when power saver mode is enabled or disabled. The function should take as argument the matrix produced by getColumnValues() and a flag named powerSaver whose value should be True to select observations where power saver mode is enabled and False otherwise.

5.Write a function to calculate the percentage of the observations where different kinds of network connection are off. This function should receive the matrix with the observations as argument, as well as a string whose values can be ‘network’, ‘mobile’, or ‘wifi’. These values determine whether the function will calculate the percentage of observations pertaining to the cell network, mobile data, or wi-fi.

Deliverables

This assignment has two deliverables:

  • A Jupyter Notebook with all the code that you wrote. Your functions should commented, in English, explaining their basic functionality and rationale. Functions and variables in your project should, as much as possible, have names that convey well their meaning.
  • A report of up to 2 pages (font size 12, single spacing, written in English, in .PDF format) discussing the following topics:
  • ?A general explanation of the solution idea for each task

    ?A summary of the obtained results

    ?Main obstacles faced during the execution of the project and how the team circumvented them

    ?A quick summary of the responsibilities of each team member

    General Requirements

  • Only use samples that were recorded after September 2017 (inclusive).
  • It must be possible to test the solutions by reading only one or a few of the data files from the dataset, just by changing the initialization of a global constant or by providing a different argument to the getColumnValues() function.
  • You can use NumPy or Pandas to store the data in memory and manipulate it. This is 100% your choice. Having said that, please indicate with a comment on the top of the Notebook which one you have decided to use.
  • Saint Cloud State University Server and Client Worksheet

    Description

    Purpose:

    ——–

    To learn how to utilize TCP client/server programming. In this case you will be required

    to implement a concurrent server that accepts connection from multiple clients.

    Requirements:

    ————-

    Using your favorite programming language, implement a client/server simple email application.

    In this application you will be running the server continuously, which means the server will

    continue to run until you decide to stop it, or kill the process.

    You will implement a client program that is capable of connecting to the server, and able to

    send/receive emails. All the client is going to be able to do is provide input to and receive

    output from the server, all the work is going to be done on the server side.

    Client:

    ——

    Once the client program is run, it should connect to the server on a socket and port that you

    chose for the server. Once that is established the client program should print a menu of choices

    to allow the user to take certain actions:

    1. Register/Login

    2. Send an Email

    3. Receive Email

    4. Quit

    1. Register/Login: In this request, you will inter a username and a password to register

    an email account, for example the following can happen:

    Please Enter a unsername: ahmed

    Please Enter a password: password1

    If the user already exists, then you will be logged in, otherwise it will create a new

    user. All of this is going to be done on the server side. The server is going to keep track

    of the users and their email.

    NOTE: You should not be able to send or receive emails unless you login/register first. Also,

    Once you register or login, you shouldn’t be able to do that again.

    2. Send an Email: This is where the client program will ask you for a usernmame to send to,

    a subject line, and a one line message to be entered. Here’s a scenario:

    To: husky

    Subject: Hello

    Contents: I really like this assignment.

    Once you finish, all this information is going to be sent to the server, or you can send it

    as you type it. The server will store the email and the subject of the email for the user to

    whom you sent it.

    3. Receive email: Once you make a selection a list of emails that were sent to you is going to be

    displayed. Here’s a scenario:

    1. Subject: “Assignment 1”

    2. Subject: “Let’s go play soccer”

    3. Subject: “The book is in”

    Enter your choice: 2

    Once you enter the choice the content of the message should show up as follows:

    Subject: Let’s go play soccer

    There is no rain or snow today, do you want to go play soccer at 4?

    Enter 1 to delete, 2 to keep: 1

    If you enter 1 the message is deleted, otherwise it’s kept for the next time you read your email.

    4. Quit: The client should keep running in a loop until you tell it to quit. Once it quits you close the

    socket and close the program.

    Server:

    ——-

    The server is a process that is running forever waiting for requests from clients, so you may run as many

    clients as you want to connect to the server. So, you can have a client to register a user, then

    send an email and quit. Another client after that, can login and do the same. A third client can

    run and read the emails. Etc.

    The server once it receives a request from the client it just performs the operation:

    1. Register a user: Store the username in an array and keep track of it as long as the server is running.

    2. Send an email: Find the username and store the email to be associated with the username.

    3. Receive an email: send back all the emails associated with the logged in user.

    4. Quit the connection with that client.

    University of Florida Write the Python Program Computer Science Task

    Description

    Write the following Python program in a Python class named Assignment7.pyand upload the

    completed program to Gradescope. The goal of this program is to take a collection of rectangles
    and display them on a canvas so that none of the rectangles overlap with each other. To
    accomplish this task, your program will define several methods and classes. Note: parameters
    and return values must be in the order they are listed in the assignment manual

    A class CustomCanvas
    CustomCanvas will have a constructor which takes two explicit arguments, height and
    width, which are expected to be of type int. The constructor will create and display a new Canvas
    object with the height and width provided. To do this, you will use Canvas, a builtin object
    defined in the python package tkinter. Documentation for the Canvas class can be found here:
    https://anzeljg.github.io/rin2/book2/2405/docs/tki…

    A class Rectangle
    Rectangle will have a constructor which takes four explicit parameters, height, width, x,
    and y. All four arguments are expected to be of type int. x and y represent the origin point of the
    given rectangle. The origin point will be the upper left corner. Parameters x and y should have
    default values of zero. The values received as parameters should be stored in instance variables
    of the same name.

    A function pack
    The pack function will have two parameters, allRect and canvasSize. allRect will be a list
    of Rectangle objects and canvasSize a tuple containing a canvas’ height and width (in that order).
    pack will take the given list of rectangles and determine a location for each rectangle so that each
    rectangle does not overlap another and each rectangle exists within the given canvas size. pack
    will then return a list of placed Rectangle objects. Each given rectangle must be included in the
    returned list. (Note: Each given rectangle is referring to the logical concept of the rectangle shape
    not the specific Rectangle object. Two Rectangle objects are logically equivalent if they have the
    same height and width. When generating the list of Rectangles to return, you can modify the
    given Rectangle objects or create new, but logically equivalent, Rectangle objects)

    A function main
    The main function will read in a filepath as a command line argument. You may assume
    the filepath is always the second command line argument given (the first being the name of the
    class being executed) The given filepath will point to a txt file containing a canvas size and
    rectangles. The first line of the given text file will contain two int’s separated by a comma.
    These int’s represent a canvas’ height and width (in that order) All following lines represent the
    height and width of an individual rectangle. main should parse the data in the file and use the
    information to create a new CustomCanvas object and a new list of Rectangles. Once generated, the list of Rectangles and the size of the canvas should be passed to the pack function. Main

    should then print each Rectangle contained in the retuned list to the instantiated CustomCanvas
    object. Each printed Rectangle should have a black border and a colored (not black or white)
    fill. Main should be called whenever Assignment7.py is run as a standalone file but not when
    Assignment7.py is loaded as a library.