[BangPypers] Fwd: Need a help on reviewing a python code.
Ramesh Rajagopal
mail2.rameshr at gmail.com
Thu Jul 16 12:19:19 CEST 2015
---------- Forwarded message ----------
From: "Ramesh Rajagopal" <mail2.rameshr at gmail.com>
Date: Jul 16, 2015 3:30 PM
Subject: Fwd: Need a help on reviewing a python code.
To: <bangpypers at python.org>
Cc:
Hello All,
It would be very helpful, if you can review a small code which I had
written in python. It is purely for my personal development perspective.
I had a got an assignment from a company, they rejected my assignment
without exactly stating what is the problem with my code. They just
conveyed that it doesn't look like a pythonic way. I would like to
understand my mistakes and improve on this. It would be good if you can
help me on this.
I am attaching the problem.txt(which has the assignment details, we need to
make assumptions), then solution as alignment.tar.gz file.
Looking forward you reply.
Regards,
Ramesh
-------------- next part --------------
Create a command line application to print out planets that are aligned.
The application should work for an arbitrary solar system. The planets in the
solar system will be define in a configuration file with the following format,
system:
- name: planet-A
theta: 0
radius: 1
period: 20
- name: planet-B
theta: 0
radius: 5
period: 30
- name: planet-C
theta: 2
radius: 10
period: 60
So each planet has a name, an initial angle (theta) given in radians, a radius
from the sun that it orbits, and length of time it takes to orbit the sun
(period). Assume that the orbit of each planet is a circle centered on the sun.
The position of each planet can be described by a radius and an angle. The
radius is constant, but the angle varies with time, i.e. at time 't' the angle
of a planet is given by,
theta + 2 pi t / period
The application will not determine the alignments itself. Instead, the
application must be able to load a set of plugins at runtime that will determine
whether a particular configuration of planets is 'aligned' according to whatever
definition the plugin uses for alignment.
The application must take arguments for the configuration file, a list of
plugins to load, and the time to calculate the alignment for. For example,
./alignment.py --config system.yaml --plugins ~/foo.py ~/bar.py ~/baz.py --time 10
and the output will have the format,
foo: planet-A, planet-B
bar: planet-B, planet-C
bar: planet-A, planet-B
baz: planet-A, planet-B, planet-C
where the application prints out the aligned planets on a new line with the name
of the plugin that return the alignment.
The application is expected to well documented and clear. Provide explanations
for the design decisions (e.g. provide rationale for why you did or did not use
a particular package). Where there is ambiguity in the problem, state the
assumptions you used to solve it. The application should support versions 2.7.x
and 3.3.x (or greater) of python. The application should come with a simple
setup.py for installation, and an example plugin that treats planets as aligned
if they are within 5 degrees of one another relative to the sun
-------------- next part --------------
A small commandline application which sets up arbitory solar system based on
the config file provided. It also prints the alignment of the planets based on
plugins provided.
Installing the application:
--------------------------
a) tar xjvf alignment-0.1.tar.gz
b) cd alignment
c) python setup.py install
How to run the application:
--------------------------
python alignment.py --config <sample_config_file> --plugins <plugin1> <plugin2> <plugin3> --time 10
e.g:
python alignment.py --config plugins/sample.yaml --plugins plugins/five_degree_alignment.py --time 10
Command Line Alignment Application
----------------------------------
This is simple command line application which sets up arbitory solar system
based on the provided configuration files. It also allows to run the plugin
during runtime to decide the alignment of planets based on the decision made
by plugins.
Design Decisions:
1) Arbitory Solar System is setup based on the given system config file. It
also exposes APIs for dynamically adding planet and removing planet from the
solar system. Hence in order to add/search/remove quickly, the planet
information has been kept under dictionary.
2) Current Arbitory Solar System planet's doesn't orbit the sun. It just gives
information from the initial position where it will be after the 'time' ticks.
This can be extended by having start() method to orbit the sun.
3) It is assumed that the period and 'time' ticks comes from the command line, has been
considered having some units of measurement. This assumption makes the
calculation easy without need to conversion.
4) InputParser class has been created to handle multiple file formats. Current
one just supports yaml parser, since we are dealing with only yaml files as of
now. This class can be extended to parse different file format as well.
5) It is assumed the plugin's file will make all the decision about whether
two planets are aligned with respect to the sun. Only desired property from
the plugin that it has to expose, print_alignment() function which prints the
alignment of planets at the point. It is with respect to plugin to decide and
print the alignment of the planets based on the input provided by alignment
application. This gives the flexiblity for the plugin developer to change
their decision as an when required.
6) Module "pyyaml" is used for parsing *.yaml file
7) Module "argparse" is used for command line parsing.
More information about the BangPypers
mailing list