Skip to content

Instantly share code, notes, and snippets.

@darylantony
Created June 20, 2018 03:51
Show Gist options
  • Save darylantony/b43f0142145322b2e3bcde110e7d22bf to your computer and use it in GitHub Desktop.
Save darylantony/b43f0142145322b2e3bcde110e7d22bf to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 39,
"metadata": {},
"outputs": [],
"source": [
"# before we do the work, order the tickets in order of size\n",
"# each row is a team member producing a sequence prediction\n",
"\n",
"sequences_of_ticket_ids = [\n",
" [1, 2, 3, 4, 5, 6, 7],\n",
" [1, 4, 3, 6, 5, 7, 2],\n",
" [2, 3, 6, 7, 4, 5, 1],\n",
" [3, 5, 7],\n",
" [4, 7, 3],\n",
"]\n",
"\n",
"# the team did some work and the hours were recorded against tickets\n",
"\n",
"recorded_hours = {\n",
" '1': 5,\n",
" '2': 7,\n",
" '4': 13,\n",
" '3': 20,\n",
" '5': 30,\n",
" '6': 24,\n",
" '7': 32\n",
"}\n",
"\n",
"# now we've done some work, we've introduced Ticket 8 and some more sequences based on size comparisons of past work\n",
"\n",
"new_sequences_of_ticket_ids = [\n",
" [2, 8, 7],\n",
" [1, 8, 6],\n",
" [3, 8, 5],\n",
" [8, 4, 5],\n",
" [8, 6, 5]\n",
"]\n",
"\n",
"sequences_lists = [sequences_of_ticket_ids, new_sequences_of_ticket_ids]\n"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [],
"source": [
"# write a function thingy that predicts the hourly value of Ticket 8?\n",
"\n",
"def prediction_thingy(id, sequences_lists, recorded_hours):\n",
" \n",
" hours = None\n",
"\n",
" # range boundaries are zero for the moment; but we could expect these to \n",
" # be influenced by the recorded hours\n",
" upper_limit = 0\n",
" upper_limits = []\n",
" \n",
" lower_limit = 0\n",
" lower_limits = []\n",
" \n",
" \n",
" for sequence_list in sequences_lists:\n",
" \n",
" for sequence in sequence_list:\n",
" \n",
" if id in sequence:\n",
" # at this point we're only interested in the sequences that contain\n",
" # the ticket id were seeking a prediction on.\n",
" \n",
" # Our resolution strategy is to take an average of the upper and lower limits\n",
" # defined by the hours recorded on comparison tickets; then we'll split the \n",
" # middle to derrive an hourly estimate for the ticket.\n",
" \n",
" \n",
" # retrieve the first index of the ticket id in the list\n",
" id_index = sequence.index(id)\n",
" \n",
" # find the nearest ticket that is predicted to be smaller than the ticket\n",
" if id_index > 0:\n",
" lower_id = sequence[id_index - 1]\n",
" lower_hours = recorded_hours[str(lower_id)]\n",
" lower_limits.append(lower_hours)\n",
" \n",
" # find the nearest ticket that is predicted to be higher than the ticket\n",
" if (id_index + 1) < len(sequence):\n",
" upper_id = sequence[id_index + 1]\n",
" upper_hours = recorded_hours[str(upper_id)]\n",
" upper_limits.append(upper_hours)\n",
" \n",
" # assuming we now have a range of values for the upper and lower limits\n",
" # else we'll get division by zero errors\n",
" if lower_limits:\n",
" lower_limit = sum(lower_limits)/len(lower_limits)\n",
" \n",
" if upper_limits:\n",
" upper_limit = sum(upper_limits)/len(upper_limits)\n",
" \n",
" \n",
" # if we have a situation where we have no upper limits, then we assume that the ticket\n",
" # is thought to be bigger than anything else in the system. \n",
" \n",
" hours = (lower_limit + upper_limit) / 2\n",
" \n",
" \n",
" return hours\n"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {},
"outputs": [],
"source": [
"prediction = prediction_thingy(8, sequences_lists, recorded_hours)"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"17.633333333333333\n"
]
}
],
"source": [
"print(prediction)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment