Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 34 additions & 29 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

143 changes: 143 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,146 @@ https://imgur.com/xSlgvtl
* Basic Wallet (basic_wallet_p)

Based on blockchain by dvf. Used under MIT license: https://github.com/dvf/blockchain

<<<<<<< HEAD
*Instructions: Click on the raw button in the upper right hand corner of
this box. Copy and paste the template into the README.md document on
your github. Fill in the titles, information and links where prompted!
Feel free to stray a bit to suit your project but try to stick to the
format as closely as possible for consistency across DSWG projects.*

# Project Name
This project is a part of the [Data Science Working
Group](http://datascience.codeforsanfrancisco.org) at [Code for San
Francisco](http://www.codeforsanfrancisco.org). Other DSWG projects can
be found at the [main GitHub
repo](https://github.com/sfbrigade/data-science-wg).
=======
*Instructions: Click on the raw button in the upper right hand corner of this box. Copy and paste the template into the README.md document on your github. Fill in the titles, information and links where prompted! Feel free to stray a bit to suit your project but try to stick to the format as closely as possible for consistency across DSWG projects.*

# Project Name
This project is a part of the [Data Science Working Group](http://datascience.codeforsanfrancisco.org) at [Code for San Francisco](http://www.codeforsanfrancisco.org). Other DSWG projects can be found at the [main GitHub repo](https://github.com/sfbrigade/data-science-wg).
>>>>>>> 8242e56594e8da50b8f6d5d49396c9c642693393

#### -- Project Status: [Active, On-Hold, Completed]

## Project Intro/Objective
<<<<<<< HEAD
The purpose of this project is ________. (Describe the main goals of the
project and potential civic impact. Limit to a short paragraph, 3-6
Sentences)
=======
The purpose of this project is ________. (Describe the main goals of the project and potential civic impact. Limit to a short paragraph, 3-6 Sentences)
>>>>>>> 8242e56594e8da50b8f6d5d49396c9c642693393

### Partner
* [Name of Partner organization/Government department etc..]
* Website for partner
* Partner contact: [Name of Contact], [slack handle of contact if any]
* If you do not have a partner leave this section out

### Methods Used
* Inferential Statistics
* Machine Learning
* Data Visualization
* Predictive Modeling
* etc.

### Technologies
* R
* Python
* D3
* PostGres, MySql
* Pandas, jupyter
* HTML
* JavaScript
* etc.

## Project Description
<<<<<<< HEAD
(Provide more detailed overview of the project. Talk a bit about your
data sources and what questions and hypothesis you are exploring. What
specific data analysis/visualization and modelling work are you using to
solve the problem? What blockers and challenges are you facing? Feel
free to number or bullet point things here)
=======
(Provide more detailed overview of the project. Talk a bit about your data sources and what questions and hypothesis you are exploring. What specific data analysis/visualization and modelling work are you using to solve the problem? What blockers and challenges are you facing? Feel free to number or bullet point things here)
>>>>>>> 8242e56594e8da50b8f6d5d49396c9c642693393

## Needs of this project

- frontend developers
- data exploration/descriptive statistics
- data processing/cleaning
- statistical modeling
- writeup/reporting
- etc. (be as specific as possible)

## Getting Started

<<<<<<< HEAD
1. Clone this repo (for help see this
[tutorial](https://help.github.com/articles/cloning-a-repository/)).
2. Raw Data is being kept [here](Repo folder containing raw data) within
this repo.

*If using offline data mention that and how they may obtain the data
from the froup)*

3. Data processing/transformation scripts are being kept [here](Repo
folder containing data processing scripts/notebooks)
4. etc...

*If your project is well underway and setup is fairly complicated (ie.
requires installation of many packages) create another "setup.md" file
and link to it here*
=======
1. Clone this repo (for help see this [tutorial](https://help.github.com/articles/cloning-a-repository/)).
2. Raw Data is being kept [here](Repo folder containing raw data) within this repo.

*If using offline data mention that and how they may obtain the data from the froup)*

3. Data processing/transformation scripts are being kept [here](Repo folder containing data processing scripts/notebooks)
4. etc...

*If your project is well underway and setup is fairly complicated (ie. requires installation of many packages) create another "setup.md" file and link to it here*
>>>>>>> 8242e56594e8da50b8f6d5d49396c9c642693393

5. Follow setup [instructions](Link to file)

## Featured Notebooks/Analysis/Deliverables
* [Notebook/Markdown/Slide Deck Title](link)
* [Notebook/Markdown/Slide DeckTitle](link)
* [Blog Post](link)


## Contributing DSWG Members

<<<<<<< HEAD
**Team Leads (Contacts) : [Full Name](https://github.com/[github
handle])(@slackHandle)**
=======
**Team Leads (Contacts) : [Full Name](https://github.com/[github handle])(@slackHandle)**
>>>>>>> 8242e56594e8da50b8f6d5d49396c9c642693393

#### Other Members:

|Name | Slack Handle |
|---------|-----------------|
|[Full Name](https://github.com/[github handle])| @johnDoe |
|[Full Name](https://github.com/[github handle]) | @janeDoe |

## Contact
<<<<<<< HEAD
* If you haven't joined the SF Brigade Slack, [you can do that
here](http://c4sf.me/slack).
* Our slack channel is `#datasci-projectname`
* Feel free to contact team leads with any questions or if you are
interested in contributing!
=======
* If you haven't joined the SF Brigade Slack, [you can do that here](http://c4sf.me/slack).
* Our slack channel is `#datasci-projectname`
* Feel free to contact team leads with any questions or if you are interested in contributing!

>>>>>>> 8242e56594e8da50b8f6d5d49396c9c642693393

42 changes: 32 additions & 10 deletions basic_block_gp/blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,19 @@ def new_block(self, proof, previous_hash=None):
"""

block = {
# TODO
"index": len(self.chain) + 1,
"timestamp":time(),
"transactions":self.current_transactions,
"proof":proof,
"previous_hash": previous_hash or self.hash(self.chain[-1]) #or self.lastblock
}

# Reset the current list of transactions
# Append the chain to the block
current_transactions = []
# Append the block to the chain
self.chain.append(block)
# Return the new block
pass
return block

def hash(self, block):
"""
Expand All @@ -48,14 +54,18 @@ def hash(self, block):
"""

# Use json.dumps to convert json into a string
string_block = json.dumps(block, sort_keys=True)#if orders change, the hash would be different
# Use hashlib.sha256 to create a hash
# It requires a `bytes-like` object, which is what
# .encode() does.
raw_hash = hashlib.sha256(string_block.encode())
# It converts the Python string into a byte string.
# We must make sure that the Dictionary is Ordered,
# or we'll have inconsistent hashes
hex_hash = raw_hash.hexdigest()

# TODO: Create the block_string
return hex_hash

# TODO: Hash this string using sha256

Expand All @@ -81,8 +91,12 @@ def proof_of_work(self, block):
:return: A valid proof for the provided block
"""
# TODO
pass
# return proof
block_string = json.dumps(block, sort_keys=True)
proof = 0
while self.valid_proof(block_string, proof) is False:
proof += 1

return proof

@staticmethod
def valid_proof(block_string, proof):
Expand All @@ -97,7 +111,11 @@ def valid_proof(block_string, proof):
:return: True if the resulting hash is a valid proof, False otherwise
"""
# TODO
pass

guess = f'{block_string}{proof}'.encode()
guess_hash = hashlib.sha256(guess).hexdigest()

return guess_hash[:3] == '000'#slice off last 6, see if it equals all zeros
# return True or False


Expand All @@ -114,21 +132,25 @@ def valid_proof(block_string, proof):
@app.route('/mine', methods=['GET'])
def mine():
# Run the proof of work algorithm to get the next proof

proof = blockchain.proof_of_work(blockchain.last_block)
# Forge the new Block by adding it to the chain with the proof
previous_hash = blockchain.hash(blockchain.last_block)
block = blockchain.new_block(proof, previous_hash)

response = {
# TODO: Send a JSON response with the new block
'new_block': block
}

return jsonify(response), 200


@app.route('/chain', methods=['GET'])
def full_chain():
response = {
# TODO: Return the chain and its current length
# TODO: Send a JSON response with the new block
'chain': blockchain.chain,
'length': len(blockchain.chain)
}

return jsonify(response), 200


Expand Down
Loading