School Assignment
I have a school assignment due tomorrow and I have been stuck on the same damn test case for three days. Before anyone asks, I have gone to office hours and asked TAs however this is a new issue and now one is around. I am making an employee database and populating it based on a csv file which I cannot view. I have been able to do everything correctly so far and the file has no errors, however I cannot pass one of the test cases. The code has to find if an employee is apart of one or more departments(it is doing this, I have checked it many times). each department object has a date of joining, if an employee is apart of more than one department, then I need to find the time between the dates in days. I am adding all of the correct data to the correct lists, so I think its an issue with how I'm calculating the difference. Point is I am really stuck and would really appreciate some help as soon as possible. If anyone is available to hop in a call that would be preferable
142 Replies
⌛ This post has been reserved for your question.
Hey @Runger! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./closeor theClose Postbutton above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
if im reading it right you have to find the days between two department join dates yes
in the comment it says returns -1 if employee is appointed in one department but it returns -2
yeah mb i just didnt change the value when i was testing something, I forgot to chang the comment but it should still work fine, unless it doesnt?
idk just pointing it out
i think theres something wrong with this part
give me a moment
i was told not to change that class, but if somethings wrong, i will gladfully rewrite my own version of it because that class looks like it makes no sense
oh so this one shouldnt be changed
so is this one that you can change
yes i can 100% change that one
and so the test fails here or
in a different method
as in
i dont know where the test fails
true
does it work tho
as in does it print the cross department for some employee
nope
what i mean is which method is responsible for printing this
cross thing to the console
cuz im guessing thats what the test checks
see thats where i get confused, when the test case is called for the unique employees, it expected a statement to be outputted because it of course, prints a statement, but here it doesnt want a print statement which leads me questioning what function is the test case actually calling
idk though
ill change anything
that cross thing in the last screenshot with the tests
what exactly does it expect to print
'difference between cross appointments'
i believe it is looking for the difference between the earliest start date and the latest start date of a given employee
that is apart of more than one appointment
so this method
seems to fail
probably
this method uses the one given to me so I think there is an issue with that last one
i just dont know what to change
interesting
do you have access to how the tests launch
and the tests code
like i just wanna check what it expects to print
it says cross: 0 but i cant find that in code
its done through moodle, all i get is a text document and i have to write code
ive been writing it in my own IDE and pasting it over
ok
I think i found something, I just dont know how to fix it or why its happening. when i check the size of the department list for a specific employee(i managed to print out the csv file to find one employee that was cross appointed to two departments) it returns 0, so somewhere, some how, i think my list is being emptied

so that would mean the print methods are ok but there is no association between employee and department
maybe
when i put that same print statement inside the else statement and at the end of the for loop, it prints 2
can you show where you put the prints
yeah, give me one second
also do you know by any chance if the first name and last name are unique in the csv
like you dont have john doe 2 times
i guess it should be unique
so that is why i have a method called 'emp_exists' it checks if it is already there, and if it is then it doesnt add it to the employee object list(emp_obj_list) again but if its not there then it does add it. this part is working, the second test case checks this and passes
but there are repeats in the csv file as some employees have more than one department and start date

at the bottom of add_emp_data, i get a 0 when i print the size

but when i print it here and check the 27th print, it is 2

oh wait
nevermind no it isnt
this is good i have found something else to figure out, progress
this decrease and increase id thing is kinda weird to me
same, i wasnt really sure what it wants me to do
i figured as long as its not super relevant to the test case, i can figure it out once it does become relevant
hmmmmm
maybe thats the problem
like it assigns the departments to the wrong id
i would have to check more
but its kinda weird that it decreases the id when it finds an employee
yeah
so this
if there already is a department it just overrides it
with that id yes
gonna check spend a few min to analyze
what this should be doing is adding another department to an existing employees department list
so does it print the same value here
if you print the employee
at the end of the loop and outside the
well loop lmao
i added another place where you can check
inside the loop
at the bottom is prints out that every employee is not cross appointed, so they only have 1 or less departments
and inside the loop
the top most print
comment
inside the loop it is the same
lemme try the last one
okay it seems to print the same thing as well
so it must not be adding the departments properly
that or its not checking correctly
ok lets run some shenanigans now :GnuTrolling:
can you do it so
for testing purposes
you create two departments for each employee
random department values
and just do that until you get people with 311 cross departments
so the test passes
to check whether
its really the problem with
saving departments or printing them
yeah i can probably try that, i think it uses a random empID so im just gonna make it so that they all have 2 departments and 2 join dates that make 311 as the difference
im kind of curious as what this will do
yes
OH SHIT
I FIGURED IT OUT
i know what its testing now
its not looking for departments
its looking for how many employees are cross appointed
so CROSS=311 is NOT refering to the days between join dates but the number of employees that have 2 or more departments
yes
thats what i meant
you need 311 employees with 2 or more dept
and then if you ahrdcore that
yes okay i got it now lemme keep testing i got an idea
okok
i got the test case to pass by hard coding it but i dont think it will hold for future test cases
ok
so its a problem with
saving
show code
this is what i changed but i can share the enitre file if you want

here is the updated file
and also the result

ok so its clearly something with this add emp data
yeah
hm
this part is interesting because
it doesnt create a department here right
so if its the first time looping
the employee doesnt get assigned a department
is that how its supposed to work
im not sure, but it seems like it should be getting a department when its added to the list
what if you add creating a department here
oh wait
yea try that
like create department and add to temp
maybe its gonna work
cuz the otehr loop seems fine for the most part
im checking that now
it still outputs CROSS=0
something is going on with the adding of departments
like when i forced the case to pass, i had three statements telling it to add a department
o
can you go back to that
hardcore part
and add a print
in each of these three things
and check which one it was calling
yeah
or with just a debugger idk
whichever u want
okay, so looking at the output(i printed the size of the list at each of the calls) it seems that this should be running properly, it calls the first two (one at the very begining and the second when adding to the list) and the size is correct and the third one is called when it is supposed to be called, so it looks like every thing should be good
most important word
should
:GnuTrolling:
actually now that im thinking
i dont think this temp object is saved to any list
oh yeah
and
maybe thats why i guess
like you got this here right
like
idk in the method add emp data it creates a temp employee and doesnt save it anywhere
and here it loops through emp obj list
and this dep thing is kinda weird cuz
for every department in an employee
it prints the first
like the one initialized above the loop
should i start adding to the emp_obj_list instead of an instance object?
check this here first i think
like
i think it should print each department
not dep
each time you have some department
idk tho
rn it prints the same department over and over
yeah thats another thing i have to get to
yea check that here first
im just gonna go grab some water real quick, ill be back in like 2 minutes and ill try that out
okay so im just gonna try and use the emp_obj_list directly instead of using temp?
first fix this part
okay
also can you add some print here to check if there is actually any employee with more than one department
if it doesnt print at all then
yea it doesnt grab the departments from the list
and i think if it wont print here then i might know the actual cause now
i dont think it will print because im not sure if thats the method being called
yeah, it didnt print
interesting
and you checked the cross 311 test yes
yes
hmmmmm
can you a test at the top
to see if its being called at all
i dont think it is but yeah sure, its worth a try
still didnt print
i think its only calling add_emp_data
ok so remind me
did it print any departments here
no, that just printed the first and last name of the employee and then "Employee is not cross-appointed" for every single one
no i meant
when you added the print for
temp get dept list size
okay hold on
no
you got 0 or some other number
when I changed print_cross_emp()?
no i mean
like you did here
but instead of emp2
temp.get dep list size
what does it print
always 0
or 1
up there is was only ever printing 0
i tried it again and it is only printing 1
so if you ran this
case3 always prints 1 yes
and case2 printed 1 too
or 2
i forgot
or case2 never prints
case 3 prints 1 and seems to be constant with all the employees and case 2 does print sometimes but it also prints 1
and it still says the employee is not cross appointed
case2 should technically always print 2 or more
yeah
because at the top of the method you got the first add department

this is the output
or some of it
im wondering why case2 prints 1
so i had changed that so that is was adding when i was adding the temp to the emp_obj_list, i added it back in at the top and ran it again and now when ever there is a case 2, both case 2 and 3 print 2
but they are still not cross appointed
so 2 departments but not cross appointed
can you show code


so you named
dep to dep3
and now it works
wt
f
lmao
i mean now it pritns 2 departments
yeah its still not passing the test case for some reason though
i wonder if something is happening once it exits the loop
uhhh
interesting
can you add something here to check whether
the employee id here
and in the add emp data
is actually the same
yeah sure
the IDs are the same
ok ig ill just run it locally
to test
wait
they are different when they have 2 or more departments
huh
now thats interesting
maybe thats why its messing up
most likely tbh
what if you change
date diff
i think when they have more than 1 department, when I am giving the id to date_diff, i am giving the id from when they first appeared in the list
to this
because previously
it was checking by
first name and last name
okay we have change
the ids are the same but instead of "employee is not cross-appointed" it says "employee not found"
wait how do you actually grab the employee id
nvm its generated
it basically just numbers the employees from 0001 - 1000
it also seems that when the employee id isnt found, the id number isn't increased, which means it repeats the id sometimes
yea somethings wrong with this id thing
adding department seems to be ok then
yeah
maybe its because it loops by dict size
and by default the
employee id is 0
and if it finds an employee that isnt in the objects yet
it gives it 0 again or something
i think that everytime i make a new employee object, i am making a new id, so i need to make sure that when an employee already exists, im not changing the id
oh yea because you got this
maybe here you need the
uhhhh
find emp id by name method
like if that first name and last name is already registered
you assign the same id
but if not you get the next id
i guess
ah okay
i got it one sec
idk im guessing lmao
arent we all
i think i might need to put a check in when im adding the departments, like if the employee already exists, search by the name and revert the id to the old one
perhaps
like i think this employee id is messing most of the
code
seems like it
try with fixing the employee id first ig
and then department
yeah
did it work
Wow 300+ messages. You really want that silver helper role.
still trying to figure it out
can you give me like
some test data
so i can run the code locally
like a file similar to the csv file?
i wanted to fill emp rows
with data so i can run the add emp data
so i need some rows for that ig
i dont really know what the file looks like, but this is the closest thing i have. its just a print out of what is read from the given file. the first number is skipped and not added to emp_rows. i also added the current version of the file
ok im just gonna steal
that part u sent
and see if its gonna recognize it
ok i made it work
basically the problem was that
you were inserting an employee each time
to the list
instead of finding an employee
in the list first
if it exists
so the fix is
search for employee in the object list
if it exists
add the department from the line
lol
simple fix
let me paste the code
Thanks so much
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
I just got kicked out of the room I was in because it was booked for a lab so I’m in the middle of heading back to my house
the code is mega ugly rn but you can clean it up
and for this data
uh
cant paste all
oh yea btw department id keeps showing me 0
because here its looping over an empty list
I’ll copy it once I’m able to get back on my computer
but that shouldnt be needed for the test to pass
oh yea i changed the employee exists to take first name and last name for arguments
instead of the whole class
but u need to change like 3 lines there
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping.
Warning: abusing this will result in moderative actions taken against you.





