2021 Exam Memo Past Paper Memo
2021 Exam Memo Past Paper Memo
DEPARTMENT OF INFORMATICS
INF 354
JULY EXAM (1) DATE: 2021-07-16
-- -- -- -- -- -- -- -- MEMO --
Module outcomes
Question (as in Study Guide) Marks Maximum
Section allocated mark
MO1 MO2 MO3 MO4 MO5 MO6 MO7
Section A X X X X X X X 10 10
Section B X X X X X X X 10 10
Section C X X X X X X X 10 10
Total 30 30
Instructions
1. This paper consists of 3 sections with several main questions (sub-sets of instructions) each.
2. Each section relates to a small semi-complete program that needs to be updated or finalised.
3. Each question relates to a file in one of the programs that you need to update or finalise.
4. Each sub-sets of instructions relates to activities and tasks in one of the files.
5. Each main question relates to a file that needs to be edited in one of the three programs you have been
provided with.
6. Answer all the questions – there are no optional questions.
7. Please read all questions, instructions and sub-sets of tasks very carefully.
8. After completing work on a relevant question, please upload ONLY the edited file to the correct upload area.
The University of Pretoria commits itself to produce academic work of integrity. I affirm that I am aware of and have
read the Rules and Policies of the University, more specifically the Disciplinary Procedure and the Tests and
Examinations Rules, which prohibit any unethical, dishonest or improper conduct during tests, assignments,
examinations and/or any other forms of assessment. I am aware that no student or any other person may assist
or attempt to assist another student, or obtain help, or attempt to obtain help from another student or any other
person during tests, assessments, assignments, examinations and/or any other forms of assessment.
BACKGROUND TO SECTION
Students are provided with a file named INF354ExamSectionA_studentCopy.zip which contains all the files
necessary to complete the questions stipulated in this section. This section contains 2 main questions each relating
to 1 file within the project provided.
In this section you will be completing the functionality to successfully log a user into an application. The Angular
application uses a list of fake users that one would need to authenticate against. The navigation bar would act as the
main indicator that the user has logged in. If and when you have completed all of the questions in this section, the
state of the user (either logged in or not) should clearly be shown in the application.
Fake users that you can use to log-into the application. This array can be found in the main.service.ts
PROJECT PREPARATION
Please complete the following questions. Please be careful to save regularly and to upload the correct files.
This Angular application makes use of the BehaviorSubject paradigm to hold the logged in state of our application.
If the value associated with the BehaviorSubject is true then the user is logged in, and if false, the user will not be
logged in.
1.1. In this question, you would be required to complete a get property that will expose the private BehaviorSubject
bs to the relevant component/s. This property should have a name getLoginState() and have a return type of
Observable<boolean>. (3 marks).
1.2. You are required to complete a function with the name Login( ). This function, should accept a user object that
will take in a parameter named user (4 marks).
• This parameter will be of type User (see the interfaces folder). In this function, you will be required to
validate the incoming user object against the users in the FAKE_USERS array.
• If the user is valid / found, the value of the BehaviorSubject should be updated to true and an Observable
of true should be returned by the function.
• If the user is invalid an Observable of false should be returned. This function should have a return type of
Observable<boolean>.
• HINT: use the of () function that rxjs provides helps to convert any value to an observable.
In this question, you will be required to complete the HTML page by implementing the correct structural directive
to conditionally show a piece of HTML content in the navigation bar if the user has either logged in or not.
• The directive will be based on the loggedIn property in the top-nav component.
• If the user has been logged in successfully, the logged in content should be displayed.
• If the user is not logged in then the ‘not logged in’ content should be displayed
Figure 2: Logged in
<!-- Complete the structural directive to show the logged in content if the user has logged in
and to show 'You're not logged in' if the user is not logged in -->
<ng-container *ngIf="loggedIn; else elseTemplate">
<!-- logged in content -->
<div class="nav-controls">
<button mat-button> Hello User</button>
<div class="image-container">
<img src="assets/user.png" alt="UserProfile">
</div>
</div>
</ng-container>
<ng-template #elseTemplate>
<!-- Not logged in content -->
<button mat-button>You're not logged In</button>
</ng-template>
<!-- /////////////////////////////////////// End ///////////////////////////////////////// -->
SECTION A TOTAL 10
BACKGROUND TO SECTION
In this section a student will be required to complete an advanced report that includes grid based charts as well as
data tables where tables are presented in other tables. The charts and tables obtain data from JSON data stored in
*.ts files within the student exam project.
Students are provided with a file named INF354ExamSectionB_studentCopy.zip which contains all the files
necessary to complete the questions stipulated in this section. This section contains 4 main questions each relating
to 1 file (refer to table 1 below) within the project provided.
After completing each question students will be required to upload only the associated file to the specific question’s
upload area.
PROJECT PREPARATION
o npm install
o npm install chart.js --save
o npm install @swimlane/ngx-charts --save
o npm install @angular/cdk --save
o npm install bootstrap
• Please note that after you have installed “npm install @swimlane/ngx-charts --save” Visual Studio Code will
indicate certain errors. Installing “npm install @angular/cdk --save" will resolve these errors.
• After installing “npm install @angular/cdk --save" several warnings will be listed. The warnings listed are just
warnings. It should not have an impact on running or executing the program when running “ng serve –o”
Note on Question 4:
• The ( tree-map-chart.component.html ) file content
has been disabled to avoid loading errors.
• The content on this page needs to be enabled after
completing the required edits in the ( tree-map-
chart.component.ts ) file to view the page.
RUNNING THE PROJECT FOR THE FIRST TIME AFTER FINAL PREPARATION (NG SERVE –O)
When running the project for the first time, you will be presented with the following screen. As you can see there
are 4 sections that needs to be completed in the aforementioned file list to ensure that this report displays all the
content found in the data folder correctly.
Please complete all the questions stipulated below to complete and populate the aforementioned screen with the
appropriate details for the successful display and completion of this report.
Please complete the following questions. Please be careful to save regularly and to upload the correct files.
1.1. Make use of a loop to access and display the main data in the multipart dataset in the JSON data so as to
display ALL the relevant data as a table (1 mark). Please make sure to assign appropriate values in the headers
to the data being displayed and assign data values by assigning the appropriate names found in the multipart
dataset (1/2 mark).
1.2. Make use of a sub-loop to access the data subset (nested data) in the multipart dataset so as to display the
data subset within each relevant associated data row linked to the data series linked to the main dataset (1
mark). Please make sure to assign appropriate values to the data being displayed in headers and data values
(1/2 mark).
<tbody>
<tr *ngFor = "let productMultiData of productMultiDataOptions">
<td>{{ productMultiData.name }}</td>
<td>
<table class="table table-bordered table-hover table-sm">
<thead class="table-primary">
<tr>
<th class="col-sm-6">Month</th>
<th class="col-sm-6">Units (Volume)</th>
</tr>
</thead>
<tbody>
<tbody>
<tr *ngFor = "let nestedMultiData of productMultiData?.series">
<td>{{ nestedMultiData.name }}</td>
<td>{{ nestedMultiData.value }}</td>
</tr>
</tbody>
Add appropriate app-routing and component routing paths to the app-routing.module.ts file ensure that all the
relevant charts and the data table is routed and displayed on the app.component.html page when apps are
assigned. Make sure to include the appropriate path as well as the appropriate component in the routing path.
1/2 each for complete path. If path is not complete but only certain sections are completed a student can
only get a maximum of 1/2 a mark. Routing is important and know how to do this properly is a concern.
Add the relevant app modules to the app.component.html to display the following appropriately on the report.
Ensure that you enable the Pie Chart, the Tree Map Chart, the Bar Chart and finally the Data Table.
<div class="container">
<div class="2col">
<div class="c2">
<div class="col-md-12">
<div class="card text-left"><div align="center">
<div class="card-body">
<h4 class="card-title border-bottom">Percentages [Q1 2021]</h4>
<!-- ---------------------------------------------------------------- -->
<!-- Add 3.1 here -->
<app-pie-chart></app-pie-chart>
</div>
</div>
</div>
</div>
</div>
<div class="c3"><div class="card text-centre"><div align="center">
<div class="card-body">
<h4 class="card-title border-bottom">Gross Volumes [Q1 2021]</h4>
<!-- ---------------------------------------------------------------- -->
<!-- Add 3.2 here -->
<app-tree-map-chart></app-tree-map-chart>
</div>
</div>
</div>
</div>
<div class="c1"><div class="col-md-12">
<div class="card text-left"><div align="center">
<div class="card-body">
<h4 class="card-title border-bottom">Fiscal Quarter [Q1 2021]: January 1 - March 31</h4>
<!-- ---------------------------------------------------------------- -->
<!-- Add 3.3 here -->
<app-bar-chart></app-bar-chart>
</div>
</div>
</div>
</div>
<div class="c1"><div class="col-md-12">
<div class="card text-left">
<div class="card-body">
<!-- ---------------------------------------------------------------- -->
<!-- Add 3.4 here -->
<app-data-tables></app-data-tables>
</div>
</div>
</div>
</div>
</div>
Add the required data assignment(s), object assignment(s), selection event assignments(s) as well as the required
label formatting assignment(s) to complete the data being accessed to the tree-map options in the tree-map-
chart.component.ts file. Complete the constructor, selection event, and label formatting to functionally complete
the TreeMapComponent so that it displays correctly on tree-map-chart.component.html AND app.component.html.
Please note that the Tree Map Chart options (tree-map-chart.component.html) have been disabled (edited out) to
avoid loading errors. To view and test the final results of the added assignments required in this question the Tree
Map options (tree-map-chart.component.html) will have to be enabled.
productSingleDataOption: any[] = []; // can add undefined with “(!)” OR “| undefined” OR “| any”
// productSingleDataOption: any[]! = [];
// productSingleDataOption: any[] = [] | any;
// productSingleDataOption: any[] = [] | undefined;
// view: any;
// This is version dependant.
// Additional option / variations that could have been added or considered (version dependant):
// view: any[] = [];
// public productSingleDataOption: [] | any = productSingleDataOption
// ----------------------------------------------------------------
// DO NOT EDIT BETWEEN THESE SECTION LINES ------------------------
gradient: boolean = false;
animations: boolean = true;
colorScheme = {
domain: ['aqua', 'blue', 'chartreuse', 'crimson', 'fuchsia', 'gray']
};
// ----------------------------------------------------------------
// DO NOT EDIT BETWEEN THESE SECTION LINES ------------------------
constructor() {
Object.assign(this, { productSingleDataOption });
}
onSelect(event: any) {
console.log(event);
}
SECTION B TOTAL 10
BACKGROUND TO SECTION
In this section a student will be required to complete complete one question; a Python Django question.
Students are provided with a file named INF354ExamSectionC_studentCopy.zip which contains all the files
necessary to complete the questions stipulated in this section. This section contains 1 main question.
After completing each question students will be required to upload only the associated file to the specific question’s
upload area.
PROJECT PREPARATION
Once you have completed the question in this section, upload the views.py file only to the Section C upload slot.
Please complete the following questions. Please be careful to save regularly and to upload the correct file.
• In the 'consultapp' folder you need to add the code for the 'views.py' file to schedule a consultation and
display the consultation listing.
• In other words, you must create a method / function that 'GET' and 'POST' the 'ScheduleConsultForm'
through the 'consult_create.html' page.
• Further, you must create a method / function to display the successfully saved consultations through the
'consult_list.html' page.
• After the 'POST' of a new consultation has been successfully saved to the database, the user must be
redirected to the 'Consultation Listing' page as demonstrated in the images below.
• NB: All the other features and functionality have already been created for you. For example, the settings,
routing, web pages, database, form, and model have already been created. You just need to update the
'views.py' file to create the consultation and display the results, as mentioned above.
• Additional 'Hints' have been added as comments in the 'views.py' file.
SOLUTION SECTION C
def index(request):
if request.method == 'POST':
form = ScheduleConsultForm(data=request.POST)
if form.is_valid():
form.save()
return redirect('consult_list')
else:
form = ScheduleConsultForm()
def consult_list(request):
consultation_list = ScheduleConsult.objects.all()
return render(request, 'consult_list.html', {
'consultation_list': consultation_list
})
SECTION C TOTAL 10