Last active
July 13, 2016 05:48
-
-
Save svanellewee/a5d7cb1e5ed828af38626e2363b94dd0 to your computer and use it in GitHub Desktop.
Calculating margin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; sve-margin | |
| (defun sve-calc-margin(cost-price margin-price) | |
| (let* ((cost-price (* 1.0 cost-price)) | |
| (margin-price (* 1.0 margin-price)) | |
| (numerator (- margin-price cost-price)) | |
| (denumerator margin-price)) | |
| (/ numerator denumerator))) | |
| (sve-comment | |
| (setq margins '(( 200 2000.00) | |
| (300 2000.00) | |
| (400 2000.00) | |
| (500 2000.00) | |
| (600 2000.00) | |
| (700 2333.33) | |
| (800 2666.67) | |
| (900 3000.00) | |
| (1000 3333.33) | |
| (1100 3666.67) | |
| (1200 4000.00) | |
| (1300 4333.33) | |
| (1400 4666.67) | |
| (1500 5000.00) | |
| (1600 5333.33) | |
| (1700 5666.67) | |
| ( 1800 6000.00))) | |
| (with-current-buffer (get-buffer-create "python-code") | |
| (erase-buffer) | |
| (python-mode) | |
| (insert "OUTPUT_CASES_FOR_COST_PRICE={") | |
| (dolist (i margins) | |
| (let* ((margin-answer (apply #'sve-calc-margin i)) | |
| (margin-percentage (* 100 margin-answer)) | |
| (cost-price (car i)) | |
| (margin-price (cadr i))) | |
| (insert (format "%s: {'margin_price': %s, 'margin': %.2f},\n" cost-price margin-price margin-answer)))) | |
| (insert "}") | |
| (indent-region (point-min) (point-max))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment