Skip to content

Commit

Permalink
Merge pull request #873 from uw-it-aca/qa
Browse files Browse the repository at this point in the history
Qa
  • Loading branch information
wmwash authored Sep 14, 2017
2 parents 3a582b7 + 1c4fab0 commit d0413fc
Show file tree
Hide file tree
Showing 26 changed files with 416 additions and 148 deletions.
21 changes: 10 additions & 11 deletions myuw/dao/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,25 @@ def is_using_file_dao():

def _is_optin_user(uwnetid):
file_path = _get_file_path("MYUW_OPTIN_SWITCH_PATH",
"optin-list.txt")

"opt_in_list.txt")
return is_netid_in_list(uwnetid, file_path)


def is_fyp_thrive_viewer(uwnetid):
def is_thrive_viewer(uwnetid, population):
file_path = _get_file_path("MYUW_MANDATORY_SWITCH_PATH",
"thrive-viewer-list.txt")

population + "_list.txt")
return is_netid_in_list(uwnetid, file_path)


def _get_file_path(settings_key, default_filename):
def _get_file_path(settings_key, filename):
file_path = getattr(settings, settings_key, None)
if not file_path:
current_dir = os.path.dirname(os.path.realpath(__file__))
if file_path:
return os.path.join(file_path, filename)

file_path = os.path.abspath(os.path.join(current_dir,
"..", "data",
default_filename))
current_dir = os.path.dirname(os.path.realpath(__file__))
file_path = os.path.abspath(os.path.join(current_dir,
"..", "data",
filename))
return file_path


Expand Down
20 changes: 7 additions & 13 deletions myuw/dao/affiliation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import traceback
from django.conf import settings
from myuw.logger.logback import log_info
from myuw.dao import is_fyp_thrive_viewer, get_netid_of_current_user
from myuw.dao import get_netid_of_current_user
from myuw.dao.schedule import get_current_quarter_schedule
from myuw.dao.pws import get_campus_of_current_user
from myuw.dao.gws import is_grad_student, is_student,\
Expand All @@ -17,6 +17,8 @@
from myuw.dao.instructor_schedule import is_instructor
from myuw.dao.uwnetid import is_clinician
from myuw.dao.enrollment import get_main_campus
from myuw.dao.thrive import get_target_group, is_fyp, is_aut_transfer,\
is_win_transfer
from myuw.dao.exceptions import IndeterminateCampusException


Expand Down Expand Up @@ -52,28 +54,24 @@ def get_all_affiliations(request):
if hasattr(request, 'myuw_user_affiliations'):
return request.myuw_user_affiliations

is_fyp = False
try:
is_fyp = is_thrive_viewer()
except Exception:
# This fails in unit tests w/o userservice
pass

data = {"grad": is_grad_student(),
"undergrad": is_undergrad_student(),
"student": is_student(),
"pce": is_pce_student(),
"staff_employee": is_staff_employee(),
"stud_employee": is_student_employee(),
"employee": is_employee(),
"fyp": is_fyp,
"fyp": is_fyp(request),
"aut_transfer": is_aut_transfer(request),
"win_transfer": is_win_transfer(request),
"faculty": is_faculty(),
"clinician": is_clinician(),
"instructor": is_instructor(request),
"seattle": is_seattle_student(),
"bothell": is_bothell_student(),
"tacoma": is_tacoma_student(),
}

# add 'official' campus info
campuses = []
try:
Expand All @@ -95,10 +93,6 @@ def get_all_affiliations(request):
return data


def is_thrive_viewer():
return is_fyp_thrive_viewer(get_netid_of_current_user())


def _get_campuses_by_schedule(schedule):
"""
Returns a dictionary indicating the campuses that the student
Expand Down
125 changes: 84 additions & 41 deletions myuw/dao/thrive.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,95 @@
import csv
import os
import datetime
import logging
from myuw.dao import is_thrive_viewer, get_netid_of_current_user
from myuw.dao.term import get_comparison_date, get_current_quarter,\
get_bod_current_term_class_start


"""
Gets the thrive message for the current day/quarter
"""
logger = logging.getLogger(__name__)
CACHE_ID = "thrive_target"
TARGET_FYP = "fyp"
TARGET_AUT_TRANSFER = "au_xfer"
TARGET_WIN_TRANSFER = "wi_xfer"
target_groups = [TARGET_AUT_TRANSFER,
TARGET_WIN_TRANSFER,
TARGET_FYP]
# the order says the priority


def get_current_message(request):
current_date = get_comparison_date(request)
current_qtr = get_current_quarter(request)
messages = _get_messages_for_quarter_dates([current_date], current_qtr)
return messages[0] if len(messages) else None
def get_target_group(request):
if hasattr(request, CACHE_ID):
return request.CACHE_ID

uwnetid = get_netid_of_current_user()
for target in target_groups:
try:
if is_thrive_viewer(uwnetid, target):
request.CACHE_ID = target
return target
except Exception:
pass
return None


def is_fyp(request):
return TARGET_FYP == get_target_group(request)

"""
Gets the thrive messages up to the currrent date in the current quarter
"""

def is_aut_transfer(request):
return TARGET_AUT_TRANSFER == get_target_group(request)


def is_win_transfer(request):
return TARGET_WIN_TRANSFER == get_target_group(request)


def get_current_message(request):
"""
Gets the thrive message for the current day in the current quarter
"""
target = get_target_group(request)
if target:
current_date = get_comparison_date(request)
current_qtr = get_current_quarter(request)
messages = _get_messages_for_quarter_dates([current_date],
current_qtr,
target)
if messages and len(messages):
return messages[0]
return None


def get_previous_messages(request):
start_date = get_bod_current_term_class_start(request).date() -\
datetime.timedelta(days=10)
"""
Gets the thrive messages up to the currrent date in the current quarter
"""
target = get_target_group(request)
if target is None:
return None

start_date = get_bod_current_term_class_start(
request).date() - datetime.timedelta(days=10)
current_date = get_comparison_date(request)
current_qtr = get_current_quarter(request)

messages = []
dates = []
if current_date >= start_date:
while start_date <= current_date:
dates.append(start_date)
start_date += datetime.timedelta(days=1)

messages = _get_messages_for_quarter_dates(dates, current_qtr)
messages = _get_messages_for_quarter_dates(dates,
current_qtr,
target)
return messages


def _get_messages_for_quarter_dates(dates, term):
def _get_messages_for_quarter_dates(dates, term, target):
path = os.path.join(
os.path.dirname(__file__),
'..', 'data', 'thrive_content.csv')
'..', 'data', "%s_%s" % (target, 'thrive_content.csv'))
rows = {}
with open(path, 'rbU') as csvfile:
reader = csv.reader(csvfile, delimiter=',', quotechar='"')
Expand All @@ -58,29 +106,27 @@ def _get_messages_for_quarter_dates(dates, term):
except IndexError:
pass

return [_make_thrive_payload(rows[row]) for row in sorted(rows.keys())]


"""
Return true if message is for current quarter and current date falls within the
display range for a given message. Message will display for 7 days.
"""
return ([_make_thrive_payload(rows[row], target)
for row in sorted(rows.keys())])


def _is_displayed(row, current_quarter, current_offset):
"""
Return true if message is for current quarter and current date
falls within the display range for a given message.
Message will display for 7 days.
"""
display_quarter = row[2]
display_offset = int(row[3])

return current_quarter == display_quarter and \
(display_offset + 7) > current_offset >= display_offset


"""
Builds a message payload from a given thrive message row
"""


def _make_thrive_payload(row):
def _make_thrive_payload(row, target):
"""
Builds a message payload from a given thrive message row
"""
try_this = None
try:
if len(row[8]) > 0:
Expand All @@ -93,17 +139,16 @@ def _make_thrive_payload(row):
'week_label': row[4],
'category_label': row[5],
'try_this': try_this,
'urls': _make_urls(row)}
'urls': _make_urls(row),
'target': target}

return payload


"""
Supports up to 5 URLS per row as defined in the spec
"""


def _make_urls(row):
"""
Supports up to 5 URLS per row as defined in the spec
"""
urls = []
for i in range(9, 17, 2):
try:
Expand All @@ -116,11 +161,9 @@ def _make_urls(row):
return urls


"""
Calculates the offset from the current date and start of quarter date
"""


def _get_offset(current_date, term):
"""
Calculates the offset from the current date and start of quarter date
"""
start_date = term.first_day_quarter
return (current_date - start_date).days
4 changes: 2 additions & 2 deletions myuw/dao/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ def is_oldmyuw_user():
return True
if is_optin_user(uwnetid) or has_newmyuw_preference(uwnetid):
return False
if is_applicant():
return True
if is_staff_employee():
return True
if is_faculty():
Expand All @@ -60,6 +58,8 @@ def is_oldmyuw_user():
return True
if is_undergrad_student():
return False
if is_applicant():
return True
return True


Expand Down
2 changes: 2 additions & 0 deletions myuw/data/au_xfer_list.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
javg001
javg003
13 changes: 13 additions & 0 deletions myuw/data/au_xfer_thrive_content.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
wk, Date,Quarter,First day (+/-),Week label,Category,Title,Message,Try This,Title 1,URL1,Title 2,URL2,Title 3,URL3,Title 4,URL4
-1,9.18.17,autumn,-10,Week 0,Learning Network,Making Connections,"Meeting others is your key to happiness—really! The more people you meet, the more you’ll feel a sense of connection and belonging at UW.",Go to three Dawg Daze events that interest you. Find someone friendly and introduce yourself. People all over campus are excited to welcome transfer students.,Dawg Daze Events for Transfer Students,http://fyp.washington.edu/ddtransfer,Dawg Daze for Tranfer Students,https://www.youtube.com/watch?v=WnoiAwN8ZhU&feature=youtu.be,,,,
1,9.25.17,autumn,-3,Week 1,Life & Wellness,Welcome to UW!,"Welcome to your first week at the University of Washington. Remember that lots of people are here to help you as you transition, not to college, but to UW. ","Talk to people in your classes, stop by one of those information tables outside the HUB, and check out the Commuter and Transfer Commons. ",Commuter and Transfer Commons,http://depts.washington.edu/hub141/,The Transfer Student Experience,https://vimeo.com/169323144/c6a1491199,,,,
2,10.2.17,autumn,4,Week 2,Learning Network,"Find Your People, Make Your Place",There are many opportunities for learning and connection outside the classroom. Build your skills and broaden your network by connecting around campus.,"Valuable connections are often right around you. Talk to a professor during office hours, strike up a conversation with someone on your commute, or explore an interest by attending a student group meeting. ",Finding your Place,https://vimeo.com/129502483/2188bcb1db,Student Activities Office,http://depts.washington.edu/thehub/sao/,,,,
3,10.9.17,autumn,11,Week 3,Study Skills,"Study Smarter, Not Harder","Studying well doesn’t always come naturally, but it’s not an impossible skill to master.","Pro tips from UW Faculty: attend all classes, review lecture notes promptly, join a study group (meet 90 mins/week), and become comfortable asking for help. Try forming a study group or attending office hours—both are a great way to deepen your understanding of course material.",Tips for Academic Success at UW,https://webster.uaa.washington.edu/asp/website/more/helpful-tips/tips-for-success-at-the-university-of-washington/,Library Resources,https://vimeo.com/129500678/d1ec4f2f39,,,,
4,10.16.17,autumn,18,Week 4,Study Skills,Write Better,Faced with your first UW paper? Put your best foot forward by visiting The Odegaard Writing and Research Center (OWRC) to amplify and refine your skills. ,Bring your paper draft to a writing consultant at OWRC — make an appointment today! ,Odegaard Writing and Research Center,https://depts.washington.edu/owrc/,Academic Writing,https://webster.uaa.washington.edu/asp/website/more/helpful-tips/writing/,Writing Resources,https://webster.uaa.washington.edu/asp/website/more/helpful-tips/writing-resources/,,
5,10.23.17,autumn,25,Week 5,Planning & Goals,Advisers Can Help!,"Developing a good relationship with advisers can be helpful on many levels. General or departmental advisers can help you plan for your major, explore classes of interest, and start to make connections to internship and career opportunities. ",Investigate information sessions or make an appointment to see an adviser. You can find out more about specific classes and check your progress toward your degree. ,UAA Advising ,https://www.washington.edu/uaa/advising/,OMAD Advising ,http://depts.washington.edu/omadcs/,Departmental Advising ,https://www.washington.edu/uaa/advising/finding-help/advising-offices-by-program/,Career & Internship Center,https://careers.uw.edu/
6,10.30.17,autumn,32,Week 6,Life & Wellness,Feeling Stressed?,"It's normal to feel anxious your first quarter at UW. Thankfully, there are easy and constructive ways to help yourself feel better.","Get outdoors, exercise, eat well, and get good sleep. Talk to supportive friends and family members. You can also try meditation or simple breathing exercises.",The Importance of a Good Night's Sleep,http://depts.washington.edu/hhpccweb/health-resource/the-importance-of-getting-a-good-nights-sleep/,Guided audio relaxation sessions,http://www.washington.edu/counseling/resources/podcasts/,Get Help at UW Health & Wellness,http://www.washington.edu/studentlife/health/,Video: Students Talk about Mental Health at UW,https://www.youtube.com/watch?v=5e6QOb_FmGk
7,11.6.17,autumn,39,Week 7,Planning & Goals,"Money, Money, Money","Funding your higher education journey can be overwhelming, but there are lots of resources to help you make the most of your time (and money!).","Scholarships may still be available for this year, and it isn't too early to start thinking about next year. Remember that for financial aid, you need to have your FAFSA completed by January 15 for the 2018-19 year. ",Scholarship Database,http://expd.uw.edu/expo/scholarships,Scholarship Advising,http://expd.uw.edu/scholarships,Student Financial Aid ,https://www.washington.edu/financialaid/,,
8,11.13.17,autumn,46,Week 8,Study Skills,Finals Prep,"The key to success, especially during finals, is to study on your own and with a study group. It’s not too late to get a group together. ","Talk to others in your class! Use your group to review lecture notes, predict test questions, and practice essay responses. ",Study Tips for Tests,https://webster.uaa.washington.edu/asp/website/more/helpful-tips/preparing-for-tests/,Tips for Reading Effectively,https://webster.uaa.washington.edu/asp/website/more/helpful-tips/effective-reading/,,,,
9,11.20.17,autumn,,,,Thanksgiving Week - no message,,,,,,,,,,
10,11.27.17,autumn,60,Week 10,Life & Wellness,Battle the Winter Blues,"With dark skies, cold weather, and increased time indoors, winter can impact both mental and physical health. Reach out if you're sad, rest if you're sick. Take steps to boost your winter wellness.","Take owernship for your health and healthy habits — take the Healthy Huskies pledge! Prevent illness and improve your mood by exercising regularly, eating healthy, getting plenty of sleep, and keeping hydrated. ",Healthy Huskies Pledge,http://washington.edu/healthyhuskies/,Light Therapy for Seasonal Affective Disorder,https://www.washington.edu/counseling/services/light-therapy-for-sad/,24-hour UW Consulting Nurse - (206) 221-2517, http://depts.washington.edu/hhpccweb/consulting-nurse-service/,Hall Health Services for Students, http://depts.washington.edu/hhpccweb/especially-for-uw-seattle-students-and-their-families/
11,12.4.17,autumn,67,Week 11,Life & Wellness,You’re Almost There!,Finish the quarter strong by making healthy habits a priority. Research has shown that better sleep = better exam grades. Take care of yourself and your brain will thank you.,"Balance individual studying with group work. Take 10 minutes to recharge every hour. Snack smart for brain power. Aim for 7-8 hours of sleep a night. And when you’re done, celebrate! ",Sleep linked to higher test scores,http://www.huffingtonpost.com/2014/06/22/sleep-hours-exam-performance_n_5516643.html,UW Recreation,https://www.washington.edu/ima/,,,,
2 changes: 2 additions & 0 deletions myuw/data/fyp_list.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
jnew
javg004
Loading

0 comments on commit d0413fc

Please sign in to comment.