Question

Python Design a class named IP_address to represent IP address objects. The IP_address class contains the...

Python

Design a class named IP_address to represent IP address objects. The IP_address class contains the following

  • A number of instance variables/fields to store a table of data. You can design them by your own.
  • A constructor that creates a table with the following:
    • a list of data.
    • ip address
    • a integer to indicate the number of elements in the sum_list/freq_list/average_list
  • A get_ip_address() method that returns the ip address

For example, consider the following code fragment:

ip_key = '192.168.0.24'
data_list =[(0, 84), (1, 84), (2, 84), (3, 84), (4, 84), (5, 84), (6, 84), (7, 84), (8, 84), (9, 84), (10, 84), (11, 84), (12, 84), (13, 84), (14, 84), (15, 84), (16, 84), (17, 84), (18, 84), (19, 84), (20, 84)]
size = 3
ip = IP_address(key, data_list, size)

The data_list contains a list of tuple objects. Each tuple consists of the time-period value and the packet-size. You should summarize this list and create a frequency list, a sum of packet-size list and an average of packet-size list. There are a lot of data for each time-period value. We calculates the total number of bytes that the source host sent for each 10-second interval. For example: the above data_list will be divided into 3 groups, such as (0-9 second), (10-19 second) and (20-29 second)

  • (0, 84), (1, 84), (2, 84), (3, 84), (4, 84), (5, 84), (6, 84), (7, 84), (8, 84), (9, 84)
  • (10, 84), (11, 84), (12, 84), (13, 84), (14, 84), (15, 84), (16, 84), (17, 84), (18, 84), (19, 84)
  • (20, 84)

Therefore, the IP_address object should contain:

  • the ip address: '192.168.0.24'
  • a frequency list: [10, 10, 1] (i.e. there are 10 elements in the first group, 10 elements in the second group and 1 element in the third group)
  • a sum of packet-size list: [840, 840, 84] (i.e. the total number of bytes that the source host sent for each 10-second interval)

And

continue from the previous question, modify the following in the IP_address class. :

  • modify the constructor and create the average of packet-size list
  • add a method named get_avg_list(). The get_avg_list() method return a list of the average packet-size lists (i.e. if the sum list is [84.0, 84.0, 84.0], then the get_avg_list() should return [[0, 84.0], [1, 84.0], [2, 84.0]]

For example, consider the following code fragment:

ip_key = '192.168.0.24'
data_list =[(0, 84), (1, 84), (2, 84), (3, 84), (4, 84), (5, 84), (6, 84), (7, 84), (8, 84), (9, 84), (10, 84), (11, 84), (12, 84), (13, 84), (14, 84), (15, 84), (16, 84), (17, 84), (18, 84), (19, 84), (20, 84)]
size = 3
ip = IP_address(key, data_list, size)

The data_list contains a list of tuple objects.

  • (0, 84), (1, 84), (2, 84), (3, 84), (4, 84), (5, 84), (6, 84), (7, 84), (8, 84), (9, 84)
  • (10, 84), (11, 84), (12, 84), (13, 84), (14, 84), (15, 84), (16, 84), (17, 84), (18, 84), (19, 84)
  • (20, 84)

Therefore, the ip object should contain:

  • ip address: '192.168.0.24'
  • an average packet-size list: [84.0, 84.0, 84.0]

For example:

ip_key = '192.168.0.24'
data_list = [(0, 84), (1, 84), (2, 84), (3, 84), (4, 84)]
size = 3
ip = IP_address(ip_key, data_list, size)
print(ip.get_avg_list())
[[0, 84.0], [1, 0], [2, 0]]
ip_key = '192.168.0.24'
data_list =[(0, 84), (1, 84), (2, 84), (3, 84), (4, 84), (5, 84), (6, 84), (7, 84), (8, 84), (9, 84), (10, 84), (11, 84), (12, 84), (13, 84), (14, 84), (15, 84), (16, 84), (17, 84), (18, 84), (19, 84), (20, 84)]
size = 3
ip = IP_address(ip_key, data_list, size)
print(ip.get_avg_list())
[[0, 84.0], [1, 84.0], [2, 84.0]]

Homework Answers

Answer #1

class IP_address:
  
def __init__(self,ip_key,data_list,size):
self.ip_key=ip_key;
self.data_list=data_list;
self.size=size;
  
def get_ip_address(self):
return self.ip_key;
  
def get_sum_list(self):
sum_list=[];
for i in range(1,size+1):
sumj=0;
for j in range(0+(10*(i-1)),10*i):
for data in self.data_list:
if(j==data[0]):
sumj=sumj+data[1];
break;
sum_list.append(sumj);
return sum_list;   
  
def get_avg_list(self):
avg_list=[];
  
for i in range(1,size+1):
avgj=0;
sumj=0;
n=0;
for j in range(0+(10*(i-1)),10*i):
for data in self.data_list:
if(j==data[0]):
sumj=sumj+data[1];
n=n+1;
break;
if(n!=0):
avg_list.append((i-1,sumj/n));
else:
avg_list.append((i-1,sumj));

  
return avg_list;   
  
ip_key = '192.168.0.24';
data_list =[(0, 84), (1, 84), (2, 84), (3, 84), (4, 84), (5, 84), (6, 84), (7, 84), (8, 84), (9, 84), (10, 84), (11, 84), (12, 84), (13, 84), (14, 84), (15, 84), (16, 84), (17, 84), (18, 84), (19, 84), (20, 84)]
size = 3;
ip = IP_address(ip_key,data_list, size);
print("sum list");
print(ip.get_sum_list());
print("average list");
print(ip.get_avg_list());

ip_key = '192.168.0.24'
data_list = [(0, 84), (1, 84), (2, 84), (3, 84), (4, 84)]
size = 3
ip = IP_address(ip_key, data_list, size)
print("sum list");
print(ip.get_sum_list());
print("average list");
print(ip.get_avg_list());

Expected output:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Python Design a class named IP_address to represent IP address objects. The IP_addressclass contains the following...
Python Design a class named IP_address to represent IP address objects. The IP_addressclass contains the following A number of instance variables/fields to store a table of data. You can design them on your own. A constructor that creates a table with the following: a list of data. IP address an integer to indicate the number of elements in the sum_list/freq_list/average_list A get_ip_address() method that returns the IP address For example, consider the following code fragment: ip_key = '192.168.0.24' data_list =[(0,...
I need a breakdown to perform in excel for numbers 7,8,9. I am unsure of how...
I need a breakdown to perform in excel for numbers 7,8,9. I am unsure of how I calculate the times. heres the data set and the questions. Calculate the probability that a flight will depart early or on time. Calculate the probability that a flight will arrive late. Calculate the probability that a flight departs late or arrives early. DEP_Delay ARR_Delay -4 0 -3 -3 0 -5 -7 -1 8 3 -1 -5 3 8 11 6 -6 0 -5...
USING C++ The purpose of this assignment is the use of 2-dimensional arrays, reading and writing...
USING C++ The purpose of this assignment is the use of 2-dimensional arrays, reading and writing text files, writing functions, and program planning and development. You will read a data file and store all of the input data in a two dimensional array. You will perform calculations on the data and store the results in the 2 dimensional array. You will sort the array and print the results in a report. Instructions You will read in the same input file...
Assuming that the population standard deviation is unknown, calculate the 95% confidence interval of the population...
Assuming that the population standard deviation is unknown, calculate the 95% confidence interval of the population mean. The following is the data. Calculating Process should be shown by Excel (Formulas). What formulas in statistics are used? 7 21 23 24 18 16 2 19 11 6 3 13 17 9 5 12 13 17 4 14 15 25 12 24 22 14 14 20 15 11 26 17 21 11 4 13 16 14 13 14 25 23 9 15...
Cork price: 16 10 15 10 17 11 14 13 11 14 11 16 18 16...
Cork price: 16 10 15 10 17 11 14 13 11 14 11 16 18 16 10 17 14 14 16 7 10 12 19 15 16 14 9 12 21 13 10 16 12 16 13 17 17 13 14 18 11 12 15 16 13 18 16 17 12 12 14 9 11 14 19 13 11 17 11 13 15 14 18 18 18 12 10 11 13 14 11 14 18 13 13 19 17 14...
Cork price: 16 10 15 10 17 11 14 13 11 14 11 16 18 16...
Cork price: 16 10 15 10 17 11 14 13 11 14 11 16 18 16 10 17 14 14 16 7 10 12 19 15 16 14 9 12 21 13 10 16 12 16 13 17 17 13 14 18 11 12 15 16 13 18 16 17 12 12 14 9 11 14 19 13 11 17 11 13 15 14 18 18 18 12 10 11 13 14 11 14 18 13 13 19 17 14...
6. Using the class data (see Blackboard file - "Class Survey Data - PSS-10 and GAS")...
6. Using the class data (see Blackboard file - "Class Survey Data - PSS-10 and GAS") calculate the correlation between the GAS – Goal disengagement and the GAS – Goal reengagement scores. Write the results in a statistical statement. 7. Using the class data calculate the correlation between the GAS – Goal disengagement and the PSS-10 scores. Write the results in a statistical statement. 8. Using the class data calculate the correlation between the GAS – Goal reengagement scores and...
The following frequency table summarizes 60 data values. What is the 80th percentile of the data?...
The following frequency table summarizes 60 data values. What is the 80th percentile of the data? The table is read from left to right. 1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 6 6 6 7 7 8 8 9 9 9 9 10 11 11 11 11 11 12 12 12 12 13 13 13 14 14 14 14 15 15 15 16 17 17 17 17 17 18 19 19 20...
Part A. In the past it has been found that the arrival time have a population...
Part A. In the past it has been found that the arrival time have a population mean value of μ = 13 and a population standard deviation of σ = 6.26. Using the given data, test whether this mean has changed. Use the critical value approach to test the hypothesis. The significance level alpha is set at 0.05 . The original data of time taken is given below. Show the process by using excel (Formulas). Part B. Test the hypothesis...
Test, at the 1% level of significance, whether the average business has more than 15 employees....
Test, at the 1% level of significance, whether the average business has more than 15 employees. Answer using excel. Employees 14 17 17 6 8 17 21 16 6 17 11 17 15 16 20 19 6 12 17 22 20 17 11 11 9 22 17 18 21 20 26 7 16 19 18 11 21 17 25 16 22 14 14 16 18 20 21 11 19 13 6 11 19 14 18 31 13 15 17 21...